Left() and Right()

Discussion in 'Basic4ppc Wishlist' started by JesseW, Oct 16, 2008.

  1. JesseW

    JesseW Active Member Licensed 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...
     
  2. klaus

    klaus Expert Licensed User

  3. agraham

    agraham Expert Licensed User

  4. JesseW

    JesseW Active Member Licensed User

    thanx guys. i'm going to like it here :)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. digitaldon37

    digitaldon37 Active Member Licensed 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"
    Code:
    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: Oct 17, 2008
  7. JesseW

    JesseW Active Member Licensed User

    Thanks everyone for the handy tips.... :sign0060:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice