CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    17

    help with reg expression

    What expression do I need to replace the second parameter in a string:

    string(blah1,blah2,blah3)

    to

    string(blah1,"blah2",blah3)

    basically it has to replace the text after the first comma but before the second comma but also it could be string(blah1,blah2) to not necessarily the second comma.

  2. #2
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: help with reg expression

    You could try...

    Code:
    string result = workingString.Replace(workingString.Split(',')[1], String.Format("\"{0}\"", workingString.Split(',')[1]));
    ...or the more verbose...

    Code:
                string result = string.Empty;
                string[] stringParts = workingString.Split(',');
    
                if (stringParts.Length > 1)
                {
                    stringParts[1] = String.Format("\"{0}\"", stringParts[1]);
                    result = String.Join(",", stringParts);
                }

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