China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-04 06:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [VBS] How to convert line breaks in text to &vbcr& characters View 2,634 Replies 18
Original Poster Posted 2007-04-14 10:02 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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
Floor 2 Posted 2007-04-14 11:40 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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.
Floor 3 Posted 2007-04-14 11:57 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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?
Floor 4 Posted 2007-04-14 12:13 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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.
Floor 5 Posted 2007-04-15 00:13 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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!!
Floor 6 Posted 2007-04-15 00:20 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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?
Floor 7 Posted 2007-04-15 00:26 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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?



; This subtitle is with English on top and Chinese at the bottom. Sometimes English may appear inside the video.
ScriptType: v4.00
Collisions: Normal
PlayResX: 384
PlayResY: 288
Timer: 100.0000


; Chinese character style
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Arial,17,&Hffffff,&H00ffff,&H000000,&H000000,-1,0,1,2,0,2,20,20,21,0,1

; English style
Style: Default2,Arial,12,&Hffffff,&H00ffff,&H000000,&H000000,-1,0,1,2,0,2,20,20,5,0,1

; When there are built-in English subtitles in the video, then use the secondary Chinese subtitle style so as not to hide the English subtitles in the video.
Style: Default3,Arial,15,&Hffffff,&H00ffff,&H000000,&H000000,-1,0,1,2,0,2,20,20,5,0,1


Of course, sometimes quotes are also involved!
Thx

[ Last edited by kich on 2007-4-15 at 12:27 AM ]
Floor 8 Posted 2007-04-15 00:31 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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!!
Floor 9 Posted 2007-04-15 00:55 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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 ]
Floor 10 Posted 2007-04-15 01:07 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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))??
Floor 11 Posted 2007-04-15 01:38 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
kich +2 2007-04-15 03:59
Floor 12 Posted 2007-04-15 04:00 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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
Floor 13 Posted 2007-04-15 05:12 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
I don't know what the relationship is with single quotes. It seems that only "" is special in the string.
Floor 14 Posted 2007-04-15 23:21 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
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!
Floor 15 Posted 2007-04-16 00:13 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
"I am a single quote 'You treat me as a string and I am not commented out!'
Can the above be commented out?"
Forum Jump: