iOS Question Differences between b4A and B4i .Contains

isonliveradio

Member
Licensed User
Longtime User
I am trying to use .indexof and substring2 etc. in my b4i code and it keeps telling me theres an error. This is based on examples from the forum. Is there a special library I need to include to use these terms?
 
Solution
Have you tried to explicitly define test2 as string?
IndexOf, Contains, etc are STRING functions!
When you are doing Teste2 = teste you are changing its definition from string into double, which is the Test definition
change the line to teste2 = teste.As(String) and see if it works

isonliveradio

Member
Licensed User
Longtime User
It’s saying that indexof and substring are undefined words. I will put the code up tomorrow. I am doing this in activity start in b4i, load a text file over the web and parse it out Into fields. Maybe it’s a problem being in that routine?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
And what error do you get ?
It would also interesting to know your code to be able to help you.
Also, it would be Very helpful for others, searching for help, or with the will to help, to have a much more significant title than "Maybe a simple question "... that says nothing about the type of issue you are facing
 
Upvote 0

isonliveradio

Member
Licensed User
Longtime User
Here is a section of the code, it works perfectly in B4A

Load a file and parse it:
    Dim cnt As Int
    Dim toggle As Int
    Dim data(2000) As String
    Dim data2(2000) As String
    Dim cnt2 As Int
    Dim test As Double
    Dim test2 As String
    Dim Stream(1000) As String
    Dim Name(1000) As String
        Dim manifest As String
    Dim SelectTotal As Int


' load available streams
    Dim Job As HttpJob
    Job.Initialize("manifest", Me)
    Job.Download("http://www.yourwebsite.com/yourtestfile.txt")
    Wait For (Job) JobDone(Job As HttpJob)
    Log (Job.JobName & " Was Downloaded")
    Log(Job.Response.ContentLength)
    total = Job.Response.ContentLength
    If Job.Success Then
        manifest = Job.GetString
    End If
    Job.Release
      
    ' split into arrays 
    data = Regex.split(CRLF, manifest)
    cnt = data.length
    cnt = cnt - 1
    toggle = 0
    cnt2 = 0
  
    ' parse out to stream() and Name()
    cnt2 = 0
    For i = 0 To cnt
        test = i/2
        test2 = test

' b4i doesnt like .contains
' i tried "indexof" even "substring2"
' both when compiled come back as error


        If test2.Contains(".") Then
            toggle = 1
            cnt2 = cnt2 + 1
        Else
            toggle = 2 
        End If
        If toggle = 2 Then Name(cnt2) = data(i)
        If toggle = 1 Then Stream(cnt2) = data(i)
    Next
    Stream(cnt2) = data(i - 1)
    Name(cnt2) = data(i - 2)
    SelectTotal = cnt2
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Have you tried to explicitly define test2 as string?
IndexOf, Contains, etc are STRING functions!
When you are doing Teste2 = teste you are changing its definition from string into double, which is the Test definition
change the line to teste2 = teste.As(String) and see if it works
 
Upvote 3
Solution

isonliveradio

Member
Licensed User
Longtime User
There’s A line under the line with .contains says something about an object as. When I compile it says .contains is a wrong word. What libraries did you enable?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Contains is a core keyword, no libs needed
 
Upvote 0

isonliveradio

Member
Licensed User
Longtime User
Have you tried to explicitly define test2 as string?
IndexOf, Contains, etc are STRING functions!
When you are doing Teste2 = teste you are changing its definition from string into double, which is the Test definition
change the line to teste2 = teste.As(String) and see if it works
Ah ha! Yes that fixed it. I am porting the code from my b4A project and must have defined Test2 as Int by mistake in the header. Thank you (and everyone else) very much for your help, couldn't see for looking.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Ah ha! Yes that fixed it. I am porting the code from my b4A project and must have defined Test2 as Int by mistake in the header. Thank you (and everyone else) very much for your help, couldn't see for looking.
then please mark the answer as the solution!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Again: Post a small project showing the issue
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Under each posted answer, if you're using a mobile to see the forum, or on the right side, there should be 2 options like in the image, and one of them is "mark as solution "
1751199712251.png


but from what I see, it has already been done
 
Upvote 0
Top