Android Question Substring2 Error java.lang.StringIndexOutOfBoundsException: length=6773; reg...

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello .
I used sbstring for parshing.
So, i read a error. whrere id problem. I know it easy , So I can t see??


thank you for helps.


B4X:
Sub Button1_Click
'Send a GET request
   job3.Initialize("Job3", Me)
   job3.Download("http://www.tcmb.gov.tr/kurlar/today.xml")
  
  
End Sub


Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   Dim tcmb As String
   Dim USD As String
   If Job.Success = True Then
     Log(Job.GetString)
    tcmb = Job.GetString
    tcmb=tcmb.SubString(200)
            Log("result1=" & tcmb.Length) '6773
         Log("result2=" & tcmb.IndexOf("US DOLLAR</CurrencyName><ForexBuying>")) '74
        
        USD= tcmb.SubString2(74,30)
    'Log(tcmb.SubString2(tcmb.IndexOf("US DOLLAR</CurrencyName><ForexBuying>"),4))
    
Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub


 

sorex

Expert
Licensed User
Longtime User
try

B4X:
USD= tcmb.SubString2(74,74+30)

oh, and xml is supposed to be handled as xml, not plain text.
so you better use an xml parser to grab the data.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The help tells you SubString2(BeginIndex As Int, EndIndex As Int).
Returns a new string which is a substring of the original string.
The new string will include the character at BeginIndex and will extend to the character at EndIndex, not including the last character.

In your case, USD= tcmb.SubString2(74,30) the EndIndex is smaller than the BeginIndex !
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I understand his confusion, in a lot of languages the 2nd parameter is the lenght and not the end position in the string.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User


oohhh ....no

ı am using .substring2(beginindex, Length)


thank you Klaus.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…