cashiba 发表于 2021-8-9 22:59:54

StringStripWS不能去除的空白?[已解决]

本帖最后由 cashiba 于 2021-8-9 23:58 编辑

Local $Str='  Is not between life and death'

$Str = StringStripWS($Str, 7)
ConsoleWrite("[" & $Str & "]" & @CRLF)

[  Is not between life and death]今天用StringStripWS整理文本,发现有些空白无法去除。
经转换原始文本发现,该空白的ascii码是Chr(161)
ASCII( )=Chr(161)      UNDEC( )=ChrW(12288)
ASCII( )=Chr(161)      UNDEC( )=ChrW(12288)这种类似的情况该如何处理?.


原网页编码:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


复制的文本如下:


  The furthest distance in the world

  Is not between life and death

  But when I stand in front of you

  Yet you don’t know that I love you

  世界上最遥远的距离

  不是生与死之间的距离

  而是我站在你面前

  你却不知道我爱你

  The furthest distance in the world

  Is not when I stand in front of you

  Yet you can’t see my love

  But when undoubtedly knowing the love from both

  Yet cannot be together

  世界上最遥远的距离

  不是我站在你面前

  你却看不到我对你的爱

  而是感受到对方坚定的爱意

  却不能在一起

  The furthest distance in the world

  Is not being apart while being in love

  But when plainly cannot resist the yearning

  Yet pretending you have never been in my heart

  世界上最遥远的距离

  不是相爱的人不能在一起

  而是明明不能停止思念

  却装作对方从未走进自己心间

  The furthest distance in the world

  Is not but using one’s indifferent heart

  To dig an uncrossible river

  For the one who loves you

  世界上最遥远的距离

  是用冷漠的心

  为爱你的人

  挖掘一条无法穿越的鸿沟

afan 发表于 2021-8-9 23:14:20

用正则试试
StringRegExpReplace($Str, '^\h+|\h+(?=\h)|\h+$', '')

cashiba 发表于 2021-8-9 23:22:15

afan 发表于 2021-8-9 23:14
用正则试试

A大的正则很完美,没问题。
{:1_206:}
难道这个内置函数不是使用的正则方法处理的?
还没有A大的方法好用
:face (31):
谢谢A大!

xzf680 发表于 2021-8-10 11:15:06

A大的正则如神一般:face (34):
https://www.autoitx.com/uc_server/avatar.php?uid=7666832&size=middle
页: [1]
查看完整版本: StringStripWS不能去除的空白?[已解决]