I have a string which some " . " characters, I have to replace the "." in very 3,6,9, 12.....the position with "VBCRLF"
How do I go about it?
:confused:
Printable View
I have a string which some " . " characters, I have to replace the "." in very 3,6,9, 12.....the position with "VBCRLF"
How do I go about it?
:confused:
Use Replace(string,".",vbcrlf) to replace all the "." in your string.
Yes i know....but how do i find the occurance of the perticular "." catecter in the string?Quote:
Originally posted by VBKNIGHT
Use Replace(string,".",vbcrlf) to replace all the "." in your string.
Code:Private Sub Command1_Click()
Dim sstr As String
Dim sreplace As String
Dim i As Integer
sstr = "................................"
For i = 1 To Len(sstr)
If (i Mod 3) = 0 Then
'MsgBox i
sreplace = sreplace + vbCrLf
Else
sreplace = sreplace + Mid(sstr, i, 1)
End If
Next
End Sub
Thanks E-Link , if i chang the String to "123.456.789.AAA.
I want to get the o/p as
123.
456.
789.
AAA.
can you help me do thath?
:confused:
oke , here they are :
Code:Private Sub Command1_Click()
Dim sstr As String
Dim sreplace As String
Dim i As Integer
sstr = "123.456.789.AAA. "
For i = 1 To Len(sstr)
sreplace = sreplace + Mid(sstr, i, 1)
If (i Mod 4) = 0 Then sreplace = sreplace + vbCrLf
Next
MsgBox sreplace
End Sub
THnaks again....but
Oh sorry i am getting confused ...infact i wanted to arrage as
for every (i mod 3)th "." a VBCRLf
ie
123.456.789.
AAA.
I used the following code but not working....
VB Code:
Private Sub Command1_Click() Dim sstr As String Dim sreplace As String Dim i As Integer sstr = "123.456.789.AAA. " For i = 1 To Len(sstr) sreplace = sreplace + Mid(sstr, i, 1) If Mid(sstr, i, 1) = "." Then j = j + 1 If (j Mod 3) = 0 Then sreplace = sreplace + vbCrLf Next MsgBox sreplace End Sub
Hi
I am totally lost here... why did the Replace function not do what u wanted???? Even if u wanted to replace a single "." with a "." and a vbcrlf u could do that with the replace function... no looping needed. And if u wanted to count all the items u can do that with the replace function also..
Regards
Stuart
IT is working ..
here is it
VB Code:
Private Function Format(sstr As String) As String 'Dim sstr As String Dim sreplace As String Dim i, j As Integer For i = 1 To Len(sstr) sreplace = sreplace + Mid(sstr, i, 1) If Mid(sstr, i, 1) = "." Then j = j + 1 If (j Mod 3) = 0 Then sreplace = sreplace + vbCrLf End If Next Format = sreplace End Function
You shouldnt name you function Format, because there already is one in VB.