how do i get the first letter out of a string?
Printable View
how do i get the first letter out of a string?
Code:strTmp = "Blah Blah"
'Cut the 1st B
strTmp = Mid$(strTmp,2)
Remove the Trim statement if you want to return a spaceCode:
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"
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
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
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]
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.
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.
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