|
-
Oct 30th, 2000, 05:09 AM
#1
Thread Starter
Addicted Member
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.
-
Oct 30th, 2000, 05:37 AM
#2
Hyperactive Member
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
-
Oct 30th, 2000, 05:50 AM
#3
Thread Starter
Addicted Member
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
-
Oct 30th, 2000, 07:18 AM
#4
_______
<?>
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, ".", "_")
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 30th, 2000, 08:03 AM
#5
Lively Member
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
-
Oct 30th, 2000, 08:32 AM
#6
Thread Starter
Addicted Member
Thanks all
Thank you all,
I have managed to get it sorted with your help.
Regards,
Rocks
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
|