|
-
April 11th, 2001, 05:23 AM
#1
Removing a character from a string
Hi
How can I remove a character from a string?
Thanks
Ehsan
-
April 11th, 2001, 05:31 AM
#2
Re: Removing a character from a string
If you want to remove all occurences of a character use the Replace function
Mystring="Hello"
MyString=replace(Mystring,"o","")
-
April 11th, 2001, 05:48 AM
#3
Re: Removing a character from a string
...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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 11th, 2001, 08:07 AM
#4
Re: Removing a character from a string
Using CopyMemory() is much faster than using Left$ and Right$ to rebuild another string.
-
April 11th, 2001, 10:03 AM
#5
Re: Removing a character from a string
All right, now I know. Thanks for sharing.
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 11th, 2001, 10:26 AM
#6
Re: Removing a character from a string
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 11th, 2001, 11:18 AM
#7
Re: Removing a character from a string
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
-
April 11th, 2001, 11:20 AM
#8
Re: Removing a character from a string
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
-
April 12th, 2001, 09:22 AM
#9
Re: Removing a character from a string
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|