-
Hi all,
I am having trouble trying to find a Char in a fixed position and then replacing it if it exists.
I was using something like this:
ElseIf Right(DSCode, 1) = "." Then
DSCstr = Replace("DSCode", ".", "_", , 1, vbTextCompare)
But It does not work (no laughing pls, I am still in the novice learning stage)
Can any one point me in the right direction pls.
Any help / advice would be great.
Thanks in advance,
Rocks.
-
Try this:
Code:
'Text1.Text = "This is my line."
Private Sub Command1_Click()
Call Char_Change(1, ".", "!")'just change this line
End Sub
Private Sub Char_Change(Number, FromWhat, ToWhat)
If Mid(Text1.Text, Len(Text1) - Number + 1, 1) = FromWhat Then
Text1.SelStart = Len(Text1) - Number
Text1.SelLength = 1
Text1.SelText = ToWhat
End If
End Sub
WP
-
Replace & Compare
Thanks For that,
I also need to do a similar process with the second char in the string changing the ':' to '@'....
But these are conditional on if the string contains either a ':' or a '.'.........
Is there another way I could do that???
Thanks in advance.....
Rocks
-
<?>
Code:
Option Explicit
Private Sub Form_Load()
Dim DSCode As String, sTemp As String
Dim sLen As Integer
'for this example this is your string
DSCode = "www.is this it or am I barking up the wrong tree."
'assuming if you are looking right 1 for a decimal
'it will always be the last character of the string
'
'in that case the length of your string will always
'be len(yourstring - 1)
'
sLen = Len(DSCode)
sLen = sLen - 1
sTemp = Left(DSCode, (sLen))
If Right(DSCode, 1) = "." Then
sTemp = Left(DSCode, sLen)
DSCode = sTemp & "_"
End If
MsgBox DSCode
End Sub
In vb6 there is a replace statement
if you know for sure there is only one "." in your
string, then you would do it like this
DSCode = Replace(DSCode, ".", "_")
-
The way I like to do this sort of thing is to use mid in both its function and statement form. See below.
Dim ThisText as string
Dim i as integer
'Example. Replace the "_" and the "@" chars with spaces.
ThisText = "This_is a line@of text"
For i = 1 to Len(ThisText)
Select case Mid(ThisText, i, 1)
case "_", "@"
mid(ThisText,i, 1) = Chr(32)
end select
next i
Cheers
Adrian
-
Thanks all
Thank you all,
I have managed to get it sorted with your help.
Regards,
Rocks