中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-04 05:27
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [VBS] How to convert line breaks in text to &vbcr& characters
Printable Version  2,631 / 18
Floor1 kich Posted 2007-04-14 10:02
中级用户 Posts 168 Credits 397
How to convert carriage returns in text into &vbcr& characters??
For example, if you read the content of a text using ReadAll, and suppose it is:

ff
fukkk
eee


Then convert it to:
ff&vbcr&fukkk&vbcr&eee

I used the Asc function for conversion, but it converted to this:
ff
&vbcr&fukkk
&vbcr&eee

Please give me some advice! Thank you
Floor2 baomaboy Posted 2007-04-14 11:40
银牌会员 Posts 554 Credits 1,513
Originally posted by kich at 2007-4-14 10:02:
How to convert the carriage returns in the text into &vbcr& characters??
For example, if you read the content of a text with ReadAll, assuming it is:

ff
fukkk
eee


Then convert it to:
ff&vbcr&fukkk&vbcr&eee

I ...


What you call a carriage return is actually carriage return + line feed. If I'm not mistaken, you only replaced the carriage return, and the line feed is still there, which is why it has that effect.
Floor3 kich Posted 2007-04-14 11:57
中级用户 Posts 168 Credits 397
Oh, right, uh, thanks! It seems like this is how to do it!!

Asking, how to define a long character from a TXT text (which may have special symbols and line breaks) as a constant in a VBS script?
Floor4 baomaboy Posted 2007-04-14 12:13
银牌会员 Posts 554 Credits 1,513
Originally posted by kich at 2007-4-14 11:57:
Oh, right, uh, thank you! It seems to be done like this!!

Ask, how to define a long character from a TXT text (which may contain special symbols and line breaks) as a constant in a VBS script?


Didn't understand what you mean.
Floor5 kich Posted 2007-04-15 00:13
中级用户 Posts 168 Credits 397
That is to say, if I have a long passage of text, I need it as a constant, and then I am going to input it into other texts (because other texts need to use these words). For example, a small piece of HTML text, I want to output it as a constant, but there are special characters in it, how to solve it?? (Line breaks and quotes, I can't treat this long passage as a constant, because there are line breaks in it)

I don't know if it's clear enough!!
Floor6 baomaboy Posted 2007-04-15 00:20
银牌会员 Posts 554 Credits 1,513
Quotation marks can be represented by chr(34).

Why don't you explain your final goal more clearly, for example, is this done for "encryption" or something else?
Floor7 kich Posted 2007-04-15 00:26
中级用户 Posts 168 Credits 397
My Purpose:
I want to make a subtitle file with both Chinese and English subtitles. But first, I need to explain the format of these subtitles. Because I need to operate on subtitles of many movies, and their formats are all the same. So, these defined formats can be made into a constant in a VBS file, and then the Chinese and English subtitles are respectively called in and slightly processed, and then the defined format description (that constant) is added at the front of these Chinese and English subtitles. But this constant is a relatively long text segment, with more than a dozen lines, and it's impossible to make it into a constant.

To express more clearly, post that format definition below and see how to make this text into a constant?



Of course, sometimes quotes are also involved!
Thx

[ Last edited by kich on 2007-4-15 at 12:27 AM ]
Floor8 kich Posted 2007-04-15 00:31
中级用户 Posts 168 Credits 397
My previous approach was to create this text as a text file and place it there, then use ReadAll to call it, but this requires that the text file must exist, which is cumbersome, a script plus a file!
If I define this text as a constant in VBS, it will be much more convenient, and I can copy it freely!!
Floor9 baomaboy Posted 2007-04-15 00:55
银牌会员 Posts 554 Credits 1,513
Originally posted by kich at 2007-4-15 00:31:
The way I used to do it was to make this text into a text file and place it there, then use ReadAll to call it, but this requires that this text file must exist, which is very troublesome, one script + one file!
If you define this text as a constant in VBS, it will be much more convenient, and you can copy it freely!!


When encountering symbols that block a single line, use the replacement method. Restore it when outputting. Hehe. Almost all viruses use this method to encrypt themselves into a single line, replacing them with some absolutely no conflicts such as chr(18), chr(30)...

[ Last edited by baomaboy on 2007-4-15 at 01:05 AM ]
Floor10 kich Posted 2007-04-15 01:07
中级用户 Posts 168 Credits 397
Oh, so it's just replacing with a non-conflicting character? Then use some special characters to replace?
Then how to replace carriage return + line feed!
I want to make a specially used VBS file, drag the file onto it, and then output a replaced file!
Then how to write the program for this VBS to handle carriage return + line feed?
Replace(content,chr(13)+char(10),cha(18))??
Floor11 baomaboy Posted 2007-04-15 01:38
银牌会员 Posts 554 Credits 1,513
Originally posted by kich at 2007-4-15 01:07:
Oh, it turns out that it's just replacing with a non-conflicting character. Then, do we use some special characters to replace?
Then how to replace the carriage return + line feed!
I want to make a dedicated VBS file for conversion. Drag the file onto it, and then...


Replace(content,chr(13)+char(10),cha(18))??
Because sometimes the carriage return and line feed are not connected individually, then Replace(content,chr(13)+char(10),cha(18)) fails.
Replace(content,chr(13),cha(28))
Replace(content,chr(13),cha(29))
Replace(content,chr(34),cha(18)) Replace " because " is used for comments in VBS. After becoming a single line, all after " becomes a comment, so it must be replaced.

Want to drag and output on it:

content=readallstr
content=Replace(content,chr(13),cha(28))
content=Replace(content,chr(13),cha(29))
content=Replace(content,chr(34),cha(18))
fso. output content

The principle is like this. In actual operation, most of the time, it is replaced by traversing with For len(content)

[ Last edited by baomaboy on 2007-4-15 at 01:39 AM ]
Floor12 kich Posted 2007-04-15 04:00
中级用户 Posts 168 Credits 397
Oh, so that's how it is. I'll go back tonight and try to figure out how to output the thing I want!! Thanks for the advice! If I have any questions, I'll come back here to ask again!! Thx
Floor13 slore Posted 2007-04-15 05:12
铂金会员 Posts 2,478 Credits 5,212
I don't know what the relationship is with single quotes. It seems that only "" is special in the string.
Floor14 kich Posted 2007-04-15 23:21
中级用户 Posts 168 Credits 397
There is such a single quote filtering. It's better. I think! Because I want to convert other texts too!!

Hehe, thank you all for your guidance!
Floor15 slore Posted 2007-04-16 00:13
铂金会员 Posts 2,478 Credits 5,212
"I am a single quote 'You treat me as a string and I am not commented out!'
Can the above be commented out?"
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023