字符串替换[已解决]
本帖最后由 仙乃日 于 2018-12-17 12:56 编辑$a=",,高,,,,A,,B,,,,S,,"
$b="高,A,B,S,"
有什么好方法将字符串$a转换成$b的样子?
具体要求是替换后的字符串的开头不能有逗号,中间无论有几个逗号只保留1个。
两次正则替换吧
StringRegExpReplace(StringRegExpReplace(",,高,,,,A,,B,,,,S,,","\,+","\,"),"^\,+","") 本帖最后由 zghwelcome 于 2018-12-16 19:36 编辑
StringRegExpReplace(',,高,,,,A,,B,,,,S,,','^,+|[,](?![^,])','')
$a=",,高,,,,A,,B,,,,S,,"
$b = StringRegExpReplace($a,"^,+|,+$"," ")
$b = StringRegExpReplace($b,",+",",")
MsgBox(0, "提示", $b) StringRegExpReplace(',,高,,,,A,,B,,,,S,,', '^,+|(?<=,),+', '') 真是高手啊,好好学习 StringRegExpReplace(',,高,,,,A,,B,,,,S,,',',*([^,]+),*','$1,')
页:
[1]