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

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 写了个去除字符串头尾非数字函数有问题

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

by thqby » 12 Feb 2024, 06:23

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

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

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

Top