Left() and Right()

JesseW

Active Member
Licensed User
Longtime User
Being a seasoned veteran to the Basic programming lang, but a noob to B4P, I was saddened to see the string manipulation functions Left() and Right() omitted from b4p. I know I can use subString() but it's just not the same, and it causes me to have to divert my train of thought from what I'm working on to coding something that's been in basic for 20+ years. Pleeze...
 

digitaldon37

Active Member
Licensed User
Longtime User
string functions

I used to keep my "VB" string functions in a text file and add them with the "Tools->Components->Add Code" menu option but when agraham released his string library I switched to that.

' These functions saved to file "strings.txt"
B4X:
Sub Left (str, n)
   Return SubString(str,0,n)
End Sub

Sub Right (str,n)
   Return SubString(str, StrLength(str)-n,n)
End Sub

Sub Mid (str,x,n)
   Return SubString(str,x-1,n)
End Sub

Sub Ltrim (str)

   Do
   x=x+1
   Loop While StrAt(str,x)=" "
   Return SubString(str,x, StrLength(str)-x)
   
End Sub

Sub Rtrim (str)
   x=StrLength(str)
   
   Do
   x=x-1
   Loop While StrAt(str,x)=" "
   Return SubString(str,0, x+1)
   
End Sub

Sub Len (str)
   Return StrLength(str)
End Sub

Sub Reverse (str)
   x=StrLength(str)+1

   Do
      newstr=newstr & SubString(str,x-1,1)
      x=x-1
   Loop While x > 0
   Return newstr
End Sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…