中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-05 01:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 空格 换成 查看 970 回复 7
楼 主 空格 换成 发表于 2007-06-20 10:34 ·  中国 湖南 长沙 电信
初级用户
★★
积分 182
发帖 75
注册 2006-10-11 00:10
19年会员
UID 65220
性别 男
状态 离线
百度贴上去的东西都把空格给缩略掉了.
想让高手帮忙写个批处理让所有的空格都换成 
这样就方便,而且好看些了.
3Q
2 发表于 2007-06-20 10:37 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
积分 3,687
发帖 1,467
注册 2005-08-08 12:00
20年会员
UID 44210
状态 离线
字符替换就可以了:
set str=%filename: = %
3 发表于 2007-06-20 13:05 ·  中国 湖南 长沙 电信
初级用户
★★
积分 182
发帖 75
注册 2006-10-11 00:10
19年会员
UID 65220
性别 男
状态 离线
- -|| 不是很懂啊..麻烦把代码全部贴出来,我自己再研究研究..

我是想把 空格 换成   再生成一个新的文件.
4 发表于 2007-06-20 16:33 ·  中国 湖北 武汉 电信
版主
★★★★★
积分 11,386
发帖 4,938
注册 2006-07-23 17:10
20年会员
UID 59080
状态 离线
sed "s/ /\ /g" yourfile
5 发表于 2007-06-22 13:11 ·  中国 山东 淄博 联通
中级用户
★★
积分 272
发帖 99
注册 2006-06-02 09:12
20年会员
UID 56414
状态 离线
很久以前做过一个


Option Explicit
'By Shilyx 2006.12.15 oversleep@163.com (2007.3.31 新加打开文件和拷贝到剪贴板功能
Dim fso, ts, target, output, objDialog
Const SpaceToNBSPRate = 1
Const TabToSpace = 8
Const ForWriting = 2
Const ForReading = 1
Const adTypeBinary = 1

If WScript.Arguments.Count < 1 Then
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "All Files|*.*"
objDialog.InitialDir = "."
If objDialog.ShowOpen = 0 Then
WScript.Quit
Else
target = objDialog.FileName
End If
Set objDialog = Nothing
Else
target = WScript.Arguments(0)
End If

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FileExists(target) Then
MsgBox "找不到文件" & target, 16, "错误"
WScript.Quit
End If

If Not IsTextFile(target) Then
WScript.echo target & "不是有效的文本文件"
WScript.Quit
End If

GetOutput
If output = target Then WScript.Quit
ChangeFileFormat target, output, SpaceToNBSPRate
If vbYes = MsgBox("输出已经复制到系统剪贴扳,并且保存在" & output & VbCrLf & "现在是否打开输出文件?",vbYesNo,"By Shilyx 2006.12.15") Then
Dim ws
Set ws = WScript.CreateObject("WScript.Shell")
ws.Run "Notepad " & Chr(32) & output & Chr(32)
End If

Function IsTextFile(file)
Dim aso, ch
IsTextFile = True
Set ASO = CreateObject("ADODB.Stream")
aso.Type = adTypeBinary
aso.Open
aso.LoadFromFile file
aso.Position = 0
Do While Not aso.EOS
ch = aso.Read(1)
If ASCB(ch) = 0 Then
IsTextFile = False
Exit Function
End If
Loop
End Function

Sub GetOutput
Dim len1, len2
output = WScript.ScriptFullName
len1 = Len(output)
len2 = Len(fso.GetFileName(output))
output = Left(output, len1 - len2)
output = output + "output.txt"
End Sub

Sub CopyToClipBoard(Text)
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.Document.ParentWindow.ClipboardData.SetData "text", Text
objIE.Quit
End Sub

Sub ChangeFileFormat(input, output, nSpace)
Dim line, Fin, Fout, NewLine, AllNewLines
Set Fin = fso.OpenTextFile(input, ForReading)
Set Fout = fso.CreateTextFile(output, ForWriting)
Do While Not Fin.AtEndOfStream
line = Fin.ReadLine
NewLine = ChangeLine(line, nSpace)
AllNewLines = AllNewLines & vbCrLf & NewLine
Fout.WriteLine(NewLine)
Loop
Fin.Close
Fout.Close
CopyToClipBoard AllNewLines
End Sub

Function ChangeLine(line, nSpace)
Dim SpaceNum
If Replace(line, " ", "") = "" Then
ChangeLine = Chr(38) + "nbsp;"
Exit Function
End If
line = RTrim(line)
SpaceNum = 0
Do While True
If Left(line, 1) = " " Then
SpaceNum = SpaceNum + 1
ElseIf Left(line, 1) = Chr(9) Then
SpaceNum = SpaceNum + TabToSpace
Else
Exit Do
End If
line = Right(line, Len(line) - 1)
Loop
ChangeLine = GetNBSP(SpaceNum * nSpace) & Trim(line)
End Function

Function GetNBSP(SpaceNum)
GetNBSP = Space(SpaceNum)
GetNBSP = Replace(GetNBSP, " ", Chr(38) + "nbsp;")
End Function


http://hi.baidu.com/shilyx/blog/item/1822b5012893f802738da5c1.html
6 发表于 2007-06-22 13:13 ·  中国 山东 淄博 联通
中级用户
★★
积分 272
发帖 99
注册 2006-06-02 09:12
20年会员
UID 56414
状态 离线
缩略掉的只是每行开头的空格
行中间和末尾的不做改动
7 发表于 2007-06-22 21:50 ·  中国 陕西 西安 电信
铂金会员
★★★★
积分 5,212
发帖 2,478
注册 2007-02-08 23:39
19年会员
UID 79003
性别 男
状态 离线
chr(38)?
VBS对这个没有转义,为什么不直接"&nbsp;"
8 发表于 2007-06-23 19:58 ·  中国 山东 淄博 联通
中级用户
★★
积分 272
发帖 99
注册 2006-06-02 09:12
20年会员
UID 56414
状态 离线
Originally posted by slore at 2007-6-22 21:50:
chr(38)?
VBS对这个没有转义,为什么不直接"&nbsp;"


这个并非是出于转义的考虑,由于这个工具在百度上发过,因此直接使用&nb..的话,在百度上显示仍然是一个空格,不利于传播,复制不来
论坛跳转: