Remove white spaces from BrightScript string

2019-07-15 14:36发布

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*$)/", "")

3条回答
The star\"
2楼-- · 2019-07-15 15:06

Using help from the comment section here is the solution

regexQuote = CreateObject("roRegex", "^\s+|\s+$", "")
newString= regexQuote.ReplaceAll(oldString, "")
print "string length:" ; len(newString)
查看更多
贼婆χ
3楼-- · 2019-07-15 15:10

Use trim()

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

BrightScript Debugger> ? len("   four   ".trim())
 4
查看更多
乱世女痞
4楼-- · 2019-07-15 15:14

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

newString = originalString.Replace(" ", "")
查看更多
登录 后发表回答