Hi
How can I remove a character from a string?
Thanks
Ehsan
Printable View
Hi
How can I remove a character from a string?
Thanks
Ehsan
If you want to remove all occurences of a character use the Replace function
Mystring="Hello"
MyString=replace(Mystring,"o","")
...and you can use replace funtion to remove only one occurence of char you want. Look at vb Help.
If you prefer to "manually" do this job, you can use instr function to find where characters you're looking for are and mid, left, and right to rebuild your string in another variable to substitute the first string...
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
Using CopyMemory() is much faster than using Left$ and Right$ to rebuild another string.
All right, now I know. Thanks for sharing.
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
It seems I have some matters using this api. Have you any suggestion?
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim x As String, y As String
y = Text1.Text
'CopyMemory x, y, Len(y) 'this copy the entire word (text1)
CopyMemory x, y, 1 'this crashes my machine
Label1.Caption = x
End Sub
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
Interpreting a string as a byte array helps. The following code copies any length of the string, just specify 2*(length of substring) as the length parameter.
option Explicit
private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
private Sub Command1_Click()
Dim x(5) as Byte, y() as Byte
y = "12345678901234567890"
CopyMemory x(0), y(0), 8
Label1.Caption = x
End Sub
Interpreting a string as a byte array helps. The following code copies any length of the string, just specify 2*(length of substring) as the length parameter.
option Explicit
private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
private Sub Command1_Click()
Dim x(10) as Byte, y() as Byte
y = "12345678901234567890"
CopyMemory x(0), y(0), 8
Label1.Caption = x
End Sub
Thanks a lot. Tomorrow I will rate you (out of vote for today!)
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.