Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
krh5150
Visitor

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
0 Kudos
4 REPLIES 4
RokuChris
Roku Employee
Roku Employee

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.

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
0 Kudos
krh5150
Visitor

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.

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
0 Kudos
krh5150
Visitor

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
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: HELP! String Functions and type mismatches

So this is the crash:
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.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.