Remove white spaces from BrightScript string

本秂侑毒 提交于 2019-12-11 03:18:27

问题


I am attempting to remove leading and trailing white spaces from my string using regex

regexQuote = CreateObject("roRegex", "/^[ ]+|[ ]+$/g+", "i")
regexQuote.ReplaceAll(noSpaceString)
print noSpaceString

[EDIT]

regexQuote = CreateObject("roRegex", "/^[ ]+|[ ]+$/g", "")
print len(noSpaceString) //this value includes leading white spaces, which I dont want

I also tried

regexQuote = CreateObject("roRegex", "/^[ ]+|[ ]+$/", "")

And tried

regexQuote = CreateObject("roRegex", "/(^\s*)|(\s*$)/", "")

回答1:


Use trim()

Use trim(), Luke! There is a string method just for the purpose:

BrightScript Debugger> ? len("   four   ".trim())
 4



回答2:


From Roku's ifString ops you can use Replace as:

newString = originalString.Replace(" ", "")



回答3:


Using help from the comment section here is the solution

regexQuote = CreateObject("roRegex", "^\s+|\s+$", "")
newString= regexQuote.ReplaceAll(oldString, "")
print "string length:" ; len(newString)


来源:https://stackoverflow.com/questions/22237143/remove-white-spaces-from-brightscript-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!