Results 1 to 5 of 5

Thread: Conditional Search and Replace?

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Conditional Search and Replace?

    I'd like to search a string for x0A and replace it with x0D0A, but only if x0A is not directly following x0D.

    Reason is, I'm receiving bytes through a socket and displaying the results in a text box.

    I thought this might be a good opportunity to use regular expressions, but not sure what the character sequence should be. Should I study regex more for this task or is there a better way to do it?

    TIA,
    Mike

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    IndexOf can do this. It return the index of the string being searched . Returns -1 if no matches . Search the forum for previous posts about IndexOf method .

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    IndexOf I understand, but I don't get how I would use in this context. Maybe I wasn't clear in my original post.

    I can receive any number of bytes over the socket, sometimes several thousand (in 1024 blocks). In this response, there are many x0A characters, which I would like to replace with x0D0A. However, there are also already x0D0A sequences also, so I don't want those to end up being X0D0D0A.

    Right now I'm searching for x0D0A, replacing with x0A, then search for x0A and replacing with x0D0A. This method just doesn't seem effecient.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Are you doing something like this ?
    VB Code:
    1. Dim s As String = "Firstx0D0ASecondx0D0AThirdx0D0A"
    2. MessageBox.Show(s.Replace("x0D0A", "x0A"))
    forget about IndexOf now .

  5. #5

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Exactly.

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