How do I get the length of a variable defined as a roString?
r = CreateObject("roRegex", "REGEX PATTERN","")
'where REGEX PATTERN is complicated regex pattern
first_match = r.Match(v_string).[0]
'v_string is a long html string
print type(first_match)
'returns roString. I expected this to be a "string" .
print len(first_match)
' crashes
I’m posting this at work (no Roku with me
) so I don’t have the exact code with me and error message with me.
I tried the this older post http://forums.roku.com/viewtopic.php?p=244210to convert object to string, but it did not work.
print len(first_match).ToStr ()
The crash is a bug that affects certain string operations when performed on objects that implement ifString but are not Strings (like roString). There is a fix in the pipeline, but until then you can convert your roString to a String with GetString:
first_match_str = first_match.GetString()
print type(first_match_str) ' prints "String"
print Len(first_match_str) ' won't crash
–Mark
First, thank you for the help.
I tried both suggestion and still got the crash.
I went with a work around to avoid the “roArray Match(String str)”
using “roList Split(String str)”
and then I took the first element (which is a type String) and applied further string manipulations
to get what I need.
Later, I’ll post details of the error for future reference.