问题
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