CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: string question

  1. #1
    Join Date
    Jul 2002
    Posts
    372

    string question

    hello,

    i have a string and i need to push the '\' char before all regex special chars like $ . * and so on.
    any idea how to do that ?

    thanks

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: string question

    The backslash character marks the start of an escape sequence so if you actually want a backslash character to appear in your string you need to use a double backslash ie '\\' which is the escape sequence for a single backslash character.

  3. #3
    Join Date
    Dec 2006
    Posts
    166

    Re: string question

    If you are using Java 1.5+ you should use Pattern.quote() to quote a string. Otherwise, just put \Q and \E around the string (that would be "\\Q" and "\\E" of course, when written out). These special forms quote the things between them.

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

Featured