Android Question charAT and " " (space value) doesn't work !

DALB

Active Member
Licensed User
Hello everyone.

I only want to do a little thing which doesn't work. Here is the code:

charAt extract:
Do While co.CharAt(0)=" "
    co=co.SubString(1)
Loop

I use it to control element of an array (or list).
This function doesn't extract the " " character:
' value' doesn't become 'value' !!!
Is there a way for making this easily ?

thks for any answer !
 
Solution
I like to know why the problem exists in B4A !
This line is wrong:
B4X:
Starter.SQL1.execquery("UPDATE bnotes SET collection='" & coo & "' WHERE id=" & nid)
It should be:
B4X:
Starter.SQL1.ExecNonQuery("UPDATE bnotes SET collection='" & coo & "' WHERE id=" & nid)
Make the change and you will be good to go. Bonne Chance

Mahares

Expert
Licensed User
Longtime User
I like to know why the problem exists in B4A !
This line is wrong:
B4X:
Starter.SQL1.execquery("UPDATE bnotes SET collection='" & coo & "' WHERE id=" & nid)
It should be:
B4X:
Starter.SQL1.ExecNonQuery("UPDATE bnotes SET collection='" & coo & "' WHERE id=" & nid)
Make the change and you will be good to go. Bonne Chance
 
Upvote 2
Solution

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Do While co.SubString2(0,1)=" "
    co=co.SubString(1)
Loop

Or
B4X:
Do While co.StartWith(" ")
    co=co.SubString(1)
Loop

Or
B4X:
Do While co.indexOf(" ")=0
    co=co.SubString(1)
Loop

But i prefear
B4X:
co=co.Trim
 
Upvote 1

DALB

Active Member
Licensed User
Thanks all for answering the complete sub code is

space extract at place 0:
    curs=Starter.SQL1.ExecQuery("SELECT * FROM bnotes")
    If curs.RowCount=0 Then Return
    For i=0 To curs.rowcount-1
        curs.Position=i
        Dim nid As Int=curs.GetInt("id")
        Dim co As String=curs.GetString("collection")
        Do While co.CharAt(0)=" "
            co=co.SubString(1)
        Loop
            Starter.SQL1.execquery("UPDATE bnotes SET collection='" & co & "' WHERE id=" & nid)
    Next

Agraham, the code doesn't want to give me the right anwser !!!
Star-Dust, each of your proposals doesn't work too !!!

!!!

I'll restart B4A...soon
 
Upvote 0

DALB

Active Member
Licensed User
After restarting B4A, the behaviour remains the same !!!
...I'm looking for...
 
Upvote 0

DALB

Active Member
Licensed User
replacing " " by chr(32) has any effect too !!!
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I haven't tested, but I'm guessing it's something weird with the cursor going on. Seems like a good time to point to #6:

And #21:

Given the weird results you're getting, I'd try changing to a ResultSet and also to just use co.Trim, like @Star-Dust proposed. No need to be overly complicated about it. (Unless you really want to save trailing spaces in your string, of course.)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
make sure the string is not null.

In any case, I believe that the problem is not. it is in the code but in the content of the string
 
Upvote 0

DALB

Active Member
Licensed User
thanks to all!
when I translate the first char with Asc(co.CharAt(0)), i can read 32 which is the asc code of the space character. But with all your proposals, i'm stuck !
I continue to look for, to understand what or where is the...bug !
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
So this should work

B4X:
log(asc(co.CharAt(0)))
Do While asc(co.CharAt(0))=32
    co=co.SubString(1)
    log(asc(co.CharAt(0)))
Loop
 
Last edited:
Upvote 0

DALB

Active Member
Licensed User
for you two, the log gives me the good answers.
so, Why can't I record them correctly in the base ?
I really don't understand what happens !!
 

Attachments

  • image_2021-09-22_160035.png
    image_2021-09-22_160035.png
    9.8 KB · Views: 88
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Why don't you do the whole thing with an sql command?
B4X:
Starter.SQL1.ExecNoQuery("UPDATE  bnotes SET collection = LTRIM(collection)")
 
Upvote 0

DALB

Active Member
Licensed User
Star-dust : Yes I've thought about this, but, even if I can find an issue out of B4A, I like to know why the problem exists in B4A !

DonManfred, here is the zip.
 

Attachments

  • charAt-test.zip
    32 KB · Views: 87
Upvote 0

DALB

Active Member
Licensed User
Damn ! even if I have 2 eyes, the brain was missing !
pfffff ! Yes, now it works !
How stupid I'm !
Thanks for looking for me ! As we say, that's better having many heads than one !
 
Upvote 0

DALB

Active Member
Licensed User
This team is extra ! Each time I come here, each time, I have answers coming from good people ! Thanks for this !
 
Upvote 0
Top