您是否有将所有特殊字符转换为空格的想法
^@^@^@^@<9C>^G^@^@*+^@^@ABD
^@^@^@^@*+^@^@<DC>_^@^@ASD
^@^@^@^@*+^@^@<DC>_^@^@ASaa
^@^@^@^@<80><C2>^A^@<C2>p^A^@ABD
od
0000000 040136 040136 040136 040136 034474 037103 043536 040136
0000020 040136 025452 040136 040136 041101 005104 040136 040136
0000040 040136 040136 025452 040136 040136 042074 037103 057137
0000060 057100 040500 042102 057012 057100 057100 057100 025100
0000100 057053 057100 036100 041504 057476 040136 040136 041101
0000120 005104 040136 040136 040136 040136 034074 037060 041474
0000140 037062 040536 040136 041474 037062 057160 057101 040500
0000160 042102 000012
0000163
cat -vET
^@^@^@^@<9C>^G^@^@*+^@^@ABD$
^@^@^@^@*+^@^@<DC>_^@^@ABD$
^@^@^@^@*+^@^@<DC>_^@^@ABD$
^@^@^@^@<80><C2>^A^@<C2>p^A^@ABD$
我尝试过
LC_ALL=C sed -e 's/[^[:blank:][:print:]]//g'
sed -r 's/[^[:print:]]//g'
或此https://unix.stackexchange.com/questions/336677/sed-and-remove-string-between-two-patterns
并且输出与预期不符
输出
ABD
ASD
ASaa
ABD
答案 0 :(得分:2)
没有“ 特殊字符”的通用定义,您可能需要指定要保留的内容,因此请删除除那些字符之外的所有字符
Sub Sample_MailEnvelope()
Application.ScreenUpdating = False
Sheets("Mail").Visible = True
Dim foliorange As Range
Set foliorange = Sheets("Countsheet").Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
For Each mycell In foliorange
Worksheets("Mail").Unprotect (".")
Sheets("Mail").Range("A7:B7") = mycell.Offset(0, 2).Value
Sheets("Mail").Range("C7:D7") = mycell.Offset(0, 3).Value
Sheets("Mail").Range("E7:F7") = mycell.Offset(0, 4).Value
Dim Sendrng As Range
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Sheets("Mail").Activate
Range("A1").Select
Set Sendrng = Selection
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
''.Introduction = "Hi," & vbNewLine & vbNewLine & "Kindly note that we have received the following transactions from you today." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine
.Introduction = ""
With .Item
.To = mycell.Offset(0, 6).Value '"email@email.com"
.CC = mycell.Offset(0, 7).Value
.BCC = ""
.Subject = "OCBC - IUTA CONFIRMATION"
.Display
.send
End With
End With
End With
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = fasle
Next mycell
Worksheets("Mail").Protect "."
Sheets("Mail").Visible = False
Application.ScreenUpdating = True
End Sub
,您可以使用文字字符模式$string =~ s/[^a-zA-Z0-9_,.-]//g; # etc, spell out what to leave
\w
我仅给出了一些标点符号章程作为示例。
您尝试使用的 POSIX字符类也可以使用
$string =~ s/[^\w,.-]//g;
或使用$string =~ s/[^[:alnum:][:punct:]]/;
样式的Perl扩展
Unicode properties给他们
\p
我们当然也可以在上面链接的综合页面上找到实际的Unicode属性。注意语法;请参阅perlrecharclass中的“ POSIX字符类”部分。
或者您可能真的要删除不可打印的字符
$string =~ s/[^\p{PosixAlnum}\p{PosixPunct}]//g;
要将其用作命令行程序(“单线”)
$string =~ s/[^[:print:]]//g;
将输出另存为perl -wpe's/\W//g' file > new_file
或
new_file
就地更改文件 (如果不想备份,请删除perl -i.bak -wpe's/[^[:print:]]//g' file
)。
如果输入是从另一个程序通过管道传递的
.bak