写了个去除字符串头尾非数字函数有问题 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

1842909997

写了个去除字符串头尾非数字函数有问题  Topic is solved

Post by 1842909997 » 12 Feb 2024, 05:15

写了个去除字符串头尾的非数字字符,但处理后输出的字符串是空白

Code: Select all

rmvfront(Str)
{
  Str1 := Substr(Str, 1, 1)
  If Str1 is not integer
    Str := Substr(Str, 2)
  Return Str
}
rmvback(Str)
{
  Str1 := Substr(Str, 0, 1)
  If Str1 is not integer
    Str := Substr(Str, 1, Strlen(Str)-1)
  Return Str
}
Rmvstr(Str) ;移除头尾非数字字符
{
Loop {
  A1:=Substr(Str, 1, 1)
  If A1 is not integer
    {Str:=rmvfront(Str)
    continue ;下个循环 
  }
  If Substr(Str, 1, 1) is integer
    break ;跳出loop
}
;msgbox % Str
Loop {
  A1:=Substr(Str, 0, 1)
  If A1 is not integer
    {Str:=rmvback(Str)
    continue ;下个循环 
  }
  If Substr(Str, 0, 1) is integer
    break ;跳出loop
}
;msgbox % Str
}

!w::
A:="25+3"
msgbox %  A
A:=Rmvstr(A)
msgbox % A
User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: 写了个去除字符串头尾非数字函数有问题

Post by thqby » 12 Feb 2024, 06:23

RegExReplace(str, "^\D+|\D+$")
Post Reply

Return to “请求帮助”