How do I cut string

Shay

Well-Known Member
Licensed User
Longtime User
I wish to remove only the left "0" in this string
(can't find how to do it)

a="0540123456"

thanks
 

boten

Active Member
Licensed User
Longtime User
if it is just the leftmost char then:

B4X:
a=a.substring(1)

if you want the first occurance of "0" (wherever it is) then:

B4X:
for i=0 to a.length-1
  if a.substring2(i,i+1)="0" then
     a=a.substring2(0,i) & a.substring(i+1)
     exit
 end if
next
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Here you go ...

a="540123456"


I'll get my coat.


Well, I was going to say "with a pair of scissors"...... :D


(Sorry about that. His question was answered so I'm just having a bit of fun. I'm tired.)
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Brad

Active Member
Licensed User
Longtime User
if you want the first occurance of "0" (wherever it is) then:

B4X:
for i=0 to a.length-1
  if a.substring2(i,i+1)="0" then
     a=a.substring2(0,i) & a.substring(i+1)
     exit
 end if
next

Here's a simpler way to remove all occurrences of a character.

a = "08934060"
a = a.Replace("0","")
returns 89346
 
Upvote 0
Top