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-06-30 19:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Word wrap issue View 2,014 Replies 21
Original Poster Posted 2007-04-27 04:41 ·  中国 福建 福州 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
How to achieve automatic line breaks in input text? For example, xxxxxxxx newline yyyyyyyy >1.tx The generated text is XXXXXXX YYYYYYY
Floor 2 Posted 2007-04-27 04:48 ·  中国 河南 洛阳 联通
新手上路
Credits 4
Posts 2
Joined 2007-04-27 04:26
19-year member
UID 86604
Gender Male
Status Offline
@echo off
:s
set /p l=
echo %l%>>1.txt
cls
goto s
Floor 3 Posted 2007-04-27 06:12 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
To enixchen:

First time using VBS to solve a problem, please bear with me.

Dim fso,wshell
Set wshell=WScript.CreateObject("Wscript.shell")
Set fso=CreateObject("scripting.filesystemobject")
Set file=fso.opentextfile("huanhang.txt")
all=file.readall
s=replace(all,"换行",vbcrlf)
file.close()
Set b=fso.CreateTextFile("new.txt")
b.Write(s)
b.Close
wshell.Run "new.txt"
Floor 4 Posted 2007-04-27 06:21 ·  中国 福建 福州 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
echo dim ws>>12.vbs
echo str = "Sorry girl:$I think I...$don't love you!">>12.vbs
echo Num = len(str)>>12.vbs
echo set ws=wscript.createobject("wscript.shell")>>12.vbs
echo ws.run("notepad.exe")>>12.vbs
echo wscript.sleep 200>>12.vbs
echo ws.appactivate "无标题 - 记事本>>12.vbs
echo wscript.sleep 500>>12.vbs

echo for i = 1 to Num>>12.vbs
echo Input = Mid(str, i, 1)>>12.vbs
echo if Input = "$" then Input = vbCr>>12.vbs
echo wscript.sleep 500>>12.vbs
echo ws.sendkeys(Input)>>12.vbs
echo next>>12.vbs

I also got it done, using ECHO````Sweat, but it will write repeatedly```
Floor 5 Posted 2007-04-27 06:36 ·  中国 福建 福州 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
echo dim ws>>12.vbs
echo str = "Sorry girl:$I think I...$don't love you!">>12.vbs
echo Num = len(str)>>12.vbs
echo set ws=wscript.createobject("wscript.shell")>>12.vbs
echo ws.run("notepad.exe")>>12.vbs
echo wscript.sleep 200>>12.vbs
echo ws.appactivate "无标题 - 记事本">>12.vbs
echo wscript.sleep 500>>12.vbs

echo for i = 1 to Num>>12.vbs
echo Input = Mid(str, i, 1)>>12.vbs
echo if Input = "$" then Input = vbCr>>12.vbs
echo wscript.sleep 500>>12.vbs
echo ws.sendkeys(Input)>>12.vbs
echo next>>12.vbs


start 12.vbs

taskkill /f /im notepad.exe

del 12.vbs


The problem of repeated writing is also solved````
Sweat, first end the Notepad process and then delete the file

```But``
Is there a way for this program to automatically save as a TXT file after outputting
don't love you!
Don't save manually
Looking forward to the expert~
Floor 6 Posted 2007-04-27 06:42 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
The building owner wants to automatically wrap lines and output content to a text file. Actually, echo XXXXX>1.txt, echo YYYY>>1.txt, ....... or vbs can all solve it. The building owner's meaning may be to wonder whether there are carriage return characters in the script, and as for this problem, I don't know either.
Floor 7 Posted 2007-04-27 07:07 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by enixchen at 2007-4-26 17:21:
echo dim ws>>12.vbs
echo str = "Sorry girl:$I think I...$don't love you!">>12.vbs
echo Num = len(str)>>12.vbs
echo set ws=wscript.createobject("wscript.shell&quo ...

I just made this VBS for demonstration, so I didn't add the part to close Notepad
Floor 8 Posted 2007-04-27 11:21 ·  中国 福建 福州 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
Elder upstairs, how to implement saving and closing????
Floor 9 Posted 2007-04-28 00:29 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by enixchen at 2007-4-26 22:21:
How to implement saving and closing? ? ?

I don't understand what you mean.

After writing to a file with VBS, it saves automatically.
Floor 10 Posted 2007-04-28 00:34 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
```@echo off&Setlocal EnableDelayedExpansion
for /f "delims=" %%a in (1.txt) do (
set str=%%a
set str=!str:换行=$_!
exit|cmd/kprompt !str!>>new_.txt
)
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
huzixuan +4 2007-04-29 23:37
Floor 11 Posted 2007-04-28 02:39 ·  中国 福建 福州 连江县 电信
初级用户
Credits 57
Posts 23
Joined 2007-04-23 05:19
19-year member
UID 86157
Gender Male
Status Offline
dim ws
str = "Sorry girl:$I think I...$don't love you!"
Num = len(str)

set ws=wscript.createobject("wscript.shell")
ws.run("notepad.exe")
wscript.sleep 200
ws.appactivate " 记事本 "
wscript.sleep 500

for i = 1 to Num

Input = Mid(str, i, 1)

if Input = "$" then Input = vbCr

wscript.sleep 500

ws.sendkeys(Input)

next

Your question is about the code by zh159. How to achieve creating a text file named XX.TXT, automatically inputting, and then automatically saving?
Floor 12 Posted 2007-05-13 07:27 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
sed "s/换行/\n/g" urfile
Floor 13 Posted 2007-05-13 13:06 ·  中国 广东 河源 电信
新手上路
Credits 5
Posts 3
Joined 2007-05-13 11:41
19-year member
UID 88384
Gender Male
Status Offline
I'm here, push it up
Floor 14 Posted 2007-05-13 13:54 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Dim WShell,fso,file
Set WShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("Outext.txt",2,True)

str = "Sorry girl:$I think I...$don't love you!"

file.Write Replace(str,"$",vbCrLf)
file.Close

Res = MsgBox("文本已经生成,是否现在查看?",1,"提示")

If Res = 1 Then WShell.run "Outext.txt"

Set file = Nothing
Set fso = Nothing
Set WShell = Nothing
Floor 15 Posted 2007-05-13 14:06 ·  中国 广东 广州 联通
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
It's very simple?

@echo off

echo Please enter the content you want to input. Press Ctrl+Z key to end.
copy con 1.txt

pause

In this way, a few lines of code can be done.
知,不觉多。不知,乃求知
Forum Jump: