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 ????
Tags (1)
0 Kudos
4 REPLIES 4
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
Tags (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.
Tags (1)
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)
Tags (1)
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)
Tags (1)
0 Kudos
Community is Temporarily in Read-Only Mode!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. You will not be able to log in or post new comments or kudos during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 12 and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

Thanks for your patience — we’re excited to share what’s next!