greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
09:20 AM
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 ????
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 ????
6 REPLIES 6

RokuKevin
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:00 PM
Re: Brightscript instr function
The string is zero indexed.... So to get a match you need to start at 0 not 1
--Kevin
i=fld.instr(0,"1234)
?"i= "; i
--Kevin
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:12 PM
Re: Brightscript instr function
From the docs.
So for this, I would assume that the start is also 1.
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.
tdurrant420
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:20 PM
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.

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:24 PM
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:
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:24 PM
Re: Brightscript instr function
Ok, if I start at zero and it returns zero, is that a no find ?

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010
12:27 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)