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: 
greubel
Visitor

Brightscript instr function

What should this return ?
fld = "1234"
i = fld.instr( 1, "1234" )
? "i = " i
return

You would think that it would be a 1 but if a field matches the search value it comes back with -1 ????
0 Kudos
6 REPLIES 6
RokuKevin
Visitor

Re: Brightscript instr function

The string is zero indexed.... So to get a match you need to start at 0 not 1

i=fld.instr(0,"1234)
?"i= "; i


--Kevin
0 Kudos
greubel
Visitor

Re: Brightscript instr function

From the docs.
8.5 Instr(position to start As Integer, text-to-search As String, substring-to-find As String) As Integer
Returns the position of a substring within a string. Returns 0 if the substring is not found. The first position is 1.


So for this, I would assume that the start is also 1.
0 Kudos
tdurrant420
Visitor

Re: Brightscript instr function

You are reading it wrong. The system is zero based. If you tell it to start looking at character 1, it will start looking AFTER character 1, not at. You need to always minus one from where you want to start.
0 Kudos
TheEndless
Channel Surfer

Re: Brightscript instr function

The standalone InStr() function is 1 based. The .InStr() method of the roString object is 0 based. No idea why they're different.

Example:
myStr = "test"
InStr( myStr, "t" ) = 1
myStr.InStr( "t" ) = 0
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
greubel
Visitor

Re: Brightscript instr function

Ok, if I start at zero and it returns zero, is that a no find ?
0 Kudos
TheEndless
Channel Surfer

Re: Brightscript instr function

"greubel" wrote:
Ok, if I start at zero and it returns zero, is that a no find ?

If using the .InStr() method (ex. myStr.Instr("test")), then -1 is no match, 0 is match at first character.
And to expand.. myStr.InStr(1, "t") = 3
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
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.