Results 1 to 9 of 9

Thread: how do i get the first letter out of a string?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    youngstown, oh
    Posts
    11
    how do i get the first letter out of a string?

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    Code:
    strTmp = "Blah Blah"
    'Cut the 1st B
    strTmp = Mid$(strTmp,2)

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Code:
        Dim str As String
        Dim sFirstChar As String
        
        str = "Hello"
        
        sFirstChar = Left(Trim(str), 1) ' returns "H"
        
        str = "   HELLO"
        
        sFirstChar = Left(Trim(str), 1) 'returns "H"
    Remove the Trim statement if you want to return a space
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    youngstown, oh
    Posts
    11
    what i am trying to do is take the first letter and take the ascii value for it and add one to it then put it back into the string and do the same for the rest of the characters and also beable to reverse is to get it back to normal

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    This should do the trick

    Code:
    Private Sub Form_Load()
        Dim s As String
        
        s = "abcdefghijklmno"
        
        ' raise characters ascii value by 1
        s = UpOneString(s)
        
        Debug.Print s
        
        ' lower characters ascii value by 1
        s = DownOneString(s)
        
        Debug.Print s
        
    End Sub
    
    Public Function UpOneString(s As String) As String
    Dim iPos As Integer
    Dim strOut As String
    Dim sChar As String
    Dim iAscVal As Integer
    
    For iPos = 1 To Len(s)
        
        ' get current character
        sChar = Mid(s, iPos, iPos + 1)
        
        ' get characters ascii value + 1
        iAscVal = (Asc(sChar) + 1)
        
        ' if ascii value is out of range then wrap around to first character
        If iAscVal > 255 Then iAscVal = 0
        
        ' change character to new value
        sChar = Chr(iAscVal)
        
        ' add to string to be returned by function
        strOut = strOut & sChar
        
    Next iPos
    
    ' return string
    UpOneString = strOut
    
    End Function
    
    Public Function DownOneString(s As String) As String
    Dim iPos As Integer
    Dim strOut As String
    Dim sChar As String
    Dim iAscVal As Integer
    
    For iPos = 1 To Len(s)
        
        ' get current character
        sChar = Mid(s, iPos, iPos + 1)
        
        ' get characters ascii value - 1
        iAscVal = (Asc(sChar) - 1)
        
        ' if ascii value if out of range than wrap around to last character value
        If iAscVal < 0 Then iAscVal = 255
        
        ' change character to new value
        sChar = Chr(iAscVal)
        
        ' add to string to be returned by function
        strOut = strOut & sChar
        
    Next iPos
    
    ' return string
    DownOneString = strOut
    
    End Function
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up Encryption

    You sopund like wish to write a simple data encryption routine rite?
    Here is the code that will add a eKey value into the source string.

    [code]
    Private Sub Command1_Click()
    Dim i As Integer
    Dim x As Integer
    Dim eStr As String
    Dim eKey As Integer
    Dim tmp As String

    'Save the encryption key
    eKey = CInt(Text2)
    'Save the source string
    tmp = Text1

    For i = 1 To Len(tmp)
    'Get the first string ASCII value
    x = Asc(tmp)
    'Add the key value into the source string
    x = x + CInt(eKey)
    'Check for > 255
    Do While x > 255
    x = x - 256
    DoEvents
    Loop
    eStr = eStr & Chr(x)
    tmp = Mid(tmp, 2)
    Next
    MsgBox eStr
    End Sub
    [code]

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    If you're making that kindof encryption, be warned, even my dog is able to figure out how that's done, and you know, he isn't even that smart

    look at kedaman's site for a cool encryption method ( http://www.kedaman.com )
    hey keda, you really should ship me that money by now

    Have fun.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi! Job,
    In my encryption I only applied 1 encryption key, for more security you can have more than 1 encryption key. Yet, this key not limited to integer, you can have some kind of string. But if you cool encryption I thing the Crytography SDK will be the most coolest.

    As a result, you can have ?? million of combination output. In my point of view, in this world there is nothing so call secure. Nothing is perfect... yet there still have somebody call himself as cracker to crack your encrypted data.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    youngstown, oh
    Posts
    11
    Thanks all. all i needed to do is have it so the average joe could not edit lock info in a text save file (ex: the STATS on a character) with out have knowldge of programing

    thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width