|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IndexOf string methodThe IndexOf string method returns the position of the first occurrence
of a character in a string. Is there a method to find the x occurrence of a character, for example, the 28th occurrence of a character in a string? Thanks Shamanda,
I don't know if you are the same as gonzosez where is asked almost the same question in the second message after yours. \\\ dim mystring as string = "I contain 70 characters" if mystring.length > 27 then dim TwentyEightchar = mystring(27) end if /// I hope this helps, Cor Show quoteHide quote "sh" <sham***@prupipe.com> schreef in bericht news:PkmEg.6252$Qf.139@newsread2.news.pas.earthlink.net... > The IndexOf string method returns the position of the first occurrence of > a character in a string. Is there a method to find the x occurrence of a > character, for example, the 28th occurrence of a character in a string? > > Thanks Won't that give me what the 27th character is? I'm looking for the
position of the 27th occurrence of some character. For example MyString = "12x34x56x78x90x12x34x56x78x90x" So the position of the 7th occurrence of x is 21 (or 20 if zero based) Cor Ligthert [MVP] wrote: Show quoteHide quote > Shamanda, > > I don't know if you are the same as gonzosez where is asked almost the same > question in the second message after yours. > > \\\ > dim mystring as string = "I contain 70 characters" > if mystring.length > 27 then > dim TwentyEightchar = mystring(27) > end if > /// > I hope this helps, > > Cor > > "sh" <sham***@prupipe.com> schreef in bericht > news:PkmEg.6252$Qf.139@newsread2.news.pas.earthlink.net... > >>The IndexOf string method returns the position of the first occurrence of >>a character in a string. Is there a method to find the x occurrence of a >>character, for example, the 28th occurrence of a character in a string? >> >>Thanks > > > Oh,
That is not to be done simple, you can use repeatly an indexof char, which is many times quicker than a indexof from a string but you would have to build code for that something as beneath not really tested see it as pseudo \\\ dim mychar as char = "x"c dim start as integer = 0 for x = 0 to 6 if start < mystring.lenth start = mystring.indexof(start, mychar) else exit for end if next /// I hope this helps, Cor Show quoteHide quote "sh" <sham***@prupipe.com> schreef in bericht news:HlnEg.8225$xp2.2617@newsread1.news.pas.earthlink.net... > Won't that give me what the 27th character is? I'm looking for the > position of the 27th occurrence of some character. For example > > MyString = "12x34x56x78x90x12x34x56x78x90x" > > So the position of the 7th occurrence of x is 21 (or 20 if zero based) > > Cor Ligthert [MVP] wrote: >> Shamanda, >> >> I don't know if you are the same as gonzosez where is asked almost the >> same question in the second message after yours. >> >> \\\ >> dim mystring as string = "I contain 70 characters" >> if mystring.length > 27 then >> dim TwentyEightchar = mystring(27) >> end if >> /// >> I hope this helps, >> >> Cor >> >> "sh" <sham***@prupipe.com> schreef in bericht >> news:PkmEg.6252$Qf.139@newsread2.news.pas.earthlink.net... >> >>>The IndexOf string method returns the position of the first occurrence of >>>a character in a string. Is there a method to find the x occurrence of a >>>character, for example, the 28th occurrence of a character in a string? >>> >>>Thanks >> >> Cor Ligthert [MVP] wrote:
> Cor, you've missed what he wants to achieve. He wants to find the 28th> \\\ > dim mystring as string = "I contain 70 characters" > if mystring.length > 27 then > dim TwentyEightchar = mystring(27) > end if > /// occurrence of a substring within a string. One possible method (watch for typos): Public Function FindNthOccurrence(source As String, substring As String, occurrence As Integer) As Integer Dim index As Integer = -1 For i As Integer = 0 to occurrence - 1 index = source.IndexOf(substring, index + 1) If index = -1 Then Exit For End If Next Return index End Function
CurrentUser
Ctype vb 2005 express > querry table in access and put contents into array Fill up string array with random characters? Dim DBh as new DBhandler vb.net 2.0 question How to read large text file ? Accessing shared member - need understanding - pretty please :-) Edit and Continue team foundataion server hard drive type |
|||||||||||||||||||||||