Results 1 to 10 of 10

Thread: Sting manipulation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120

    Exclamation Sting manipulation

    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?

  2. #2
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619
    Use Replace(string,".",vbcrlf) to replace all the "." in your string.

    If a post has helped you then Please Rate it!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by VBKNIGHT
    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?

  4. #4
    Addicted Member E-Link's Avatar
    Join Date
    Nov 2001
    Location
    INA
    Posts
    242
    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    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?





  6. #6
    Addicted Member E-Link's Avatar
    Join Date
    Nov 2001
    Location
    INA
    Posts
    242
    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    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:
    1. Private Sub Command1_Click()
    2. Dim sstr As String
    3. Dim sreplace As String
    4. Dim i As Integer
    5.  
    6. sstr = "123.456.789.AAA. "
    7.  
    8. For i = 1 To Len(sstr)
    9.     sreplace = sreplace + Mid(sstr, i, 1)
    10.     If Mid(sstr, i, 1) = "." Then j = j + 1
    11.     If (j Mod 3) = 0 Then sreplace = sreplace + vbCrLf
    12. Next
    13. MsgBox sreplace
    14. End Sub

  8. #8
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120

    I got it !!!

    IT is working ..
    here is it
    VB Code:
    1. Private Function Format(sstr As String) As String
    2. 'Dim sstr As String
    3. Dim sreplace As String
    4. Dim i, j As Integer
    5.  
    6. For i = 1 To Len(sstr)
    7.     sreplace = sreplace + Mid(sstr, i, 1)
    8.     If Mid(sstr, i, 1) = "." Then
    9.         j = j + 1
    10.         If (j Mod 3) = 0 Then sreplace = sreplace + vbCrLf
    11.     End If
    12. Next
    13. Format = sreplace
    14. End Function

  10. #10
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    You shouldnt name you function Format, because there already is one in VB.
    You just proved that sig advertisements work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width