krh5150
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2013
01:57 PM
HELP! String Functions and type mismatches
Hi,
I'm trying to take the returned results of string functions like uCase(string), lCase(string), and len(string) and store them into variables, like below...
word = "TEST"
letterTotal = CreateObject("roInt")
letterTotal = len(word)
firstChar = left(word, 1)
remainingChars = right(word, len(word) - (len(word) - 1))
I've individually tested each string function and I always end up with a type mismatch error.
PLEASE HELP!
Thanks,
Kevin
I'm trying to take the returned results of string functions like uCase(string), lCase(string), and len(string) and store them into variables, like below...
word = "TEST"
letterTotal = CreateObject("roInt")
letterTotal = len(word)
firstChar = left(word, 1)
remainingChars = right(word, len(word) - (len(word) - 1))
I've individually tested each string function and I always end up with a type mismatch error.
PLEASE HELP!
Thanks,
Kevin
4 REPLIES 4


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2013
02:40 PM
Re: HELP! String Functions and type mismatches
That all works fine for me. It might help if you could share the actual error you're seeing and what firmware version it's happening in.
yields:
word = "TEST"
letterTotal = CreateObject("roInt")
letterTotal = len(word)
? type(letterTotal)
? letterTotal.ToStr()
firstChar = left(word, 1)
remainingChars = right(word, len(word) - (len(word) - 1))
? type(remainingChars)
? remainingChars
yields:
------ Running ------
Integer
4
String
T
krh5150
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2013
03:02 PM
Re: HELP! String Functions and type mismatches
Hi Chris,
My code is below. I'm trying to create a function that will take a word or phrase and print/return in camelcase for my search engine.
My code is below. I'm trying to create a function that will take a word or phrase and print/return in camelcase for my search engine.
Function convertCamelCase(term as string) as void
if term = invalid
'return invalid
end if
regEx = CreateObject("roRegex", " ", "")
termList = CreateObject("roArray")
termList = regEx.Split(term)
print termList
for index = 0 To termList.Count() Step 1
word = termList[index]
if not word = "" then
letterCount = CreateObject("roInt")
letterCount = len(word)
firstChar = left(word, 1)
if len(word) = 1 then
remainingChars = right(word, letterCount - 1)
firstChar = uCase(firstChar)
updatedWord = firstChar + remainingChars
termList[index] = updatedWord
else
termList[index] = uCase(firstChar)
end if
end if
next
End Function
krh5150
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2013
03:14 PM
Re: HELP! String Functions and type mismatches
Hi Chris,
Basically, what I'm trying to do a take in a string that may contain 1 word or a phrase (such as a full name) and camel case it.
I'm splitting where there are any spaces into an array. Then, I traverse through the array, take each word, grab the first letter in the word, make it uppercase, then reset the current index value of the array to the first letter that is uppercased and the remaining letters of the same word.
Kevin
Basically, what I'm trying to do a take in a string that may contain 1 word or a phrase (such as a full name) and camel case it.
I'm splitting where there are any spaces into an array. Then, I traverse through the array, take each word, grab the first letter in the word, make it uppercase, then reset the current index value of the array to the first letter that is uppercased and the remaining letters of the same word.
Kevin


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2013
03:24 PM
Re: HELP! String Functions and type mismatches
So this is the crash:
It's telling you the error is on this line:
And if you look down a few lines you see that word is invalid:
So you're passing an invalid to a function that expects a string. And the reason is that your for loop is walking off the end of the termList array.
Type Mismatch. (runtime error &h18) in ...AA1xHgyO/pkg:/source/main.brs(45)
045: letterCount = len(word)
Backtrace:
Function convertcamelcase(term As ) As
file/line: /tmp/plugin/M...AA1xHgyO/pkg:/source/main.brs(45)
Function main() As
file/line: /tmp/plugin/M...AA1xHgyO/pkg:/source/main.brs(61)
Local Variables:
term &h0100 String (VT_STR_CONST) val:hello world
global &h0020 rotINTERFACE:ifGlobal
m &h0010 bsc:roAssociativeArray, refcnt=3
regex &h0010 bsc:roRegex, refcnt=1
termlist &h0010 bsc:roList, refcnt=1
index &h0002 Integer val:2
word &h0080 Invalid val:invalid
lettercount &h0010 bsc:roInt, refcnt=1
firstchar &h8010 bsc:roString (2.1 was String), refcnt=1
remainingchars &h0000 <uninitialized> val:Uninitialized
updatedword &h0000 <uninitialized> val:Uninitialized
It's telling you the error is on this line:
letterCount = len(word)
And if you look down a few lines you see that word is invalid:
word &h0080 Invalid val:invalid
So you're passing an invalid to a function that expects a string. And the reason is that your for loop is walking off the end of the termList array.