locked
replacing with double quotes RRS feed

  • Question

  • User995576430 posted

    can someone please send the csharp code to convert the first string like the second one

    a.b.c

    "a"."b"."c"

    Monday, February 9, 2015 11:18 PM

Answers

  • User2103319870 posted

    xavier.r.fernando

    can someone please send the csharp code to convert the first string like the second one

    a.b.c

    "a"."b"."c"

    You can try with the below code

    //Your string
    string s = "a.b.c";
    //Add double quotes
    string replaced = "\""+ s.Replace(".", "\".\"")+"\"";  //This line outputs "a"."b"."c"
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 11:32 PM
  • User-434868552 posted

    @xavier.r.fer...   TIMTOWTDI

    Why would you want to?

    Do you simply mean how to code your string?

    Console.WriteLine(@"""a"".""b"".""c""");

    output:

    "a"."b"."c"

    xavier.r.fer..., some clarification from you would be helpful.

    Where is your   a.b.c    ?   in code?  in a data file?

    http://weblogs.asp.net/gerrylowry/clarity-is-important-both-in-question-and-in-answer 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 11:51 PM
  • User1271516709 posted

    Hi Xavier.r.Fernando,

    Please try below code it will work with any string that have . as separator.

     class Program
      {
        public static string test = "a.b.c";
        static void Main(string[] args)
        {
          var array = test.Split(new char[]{'.'}, StringSplitOptions.RemoveEmptyEntries);
          string result = string.Join("\".\"", array);
          result = "\"" + result + "\"";
          Console.WriteLine(result);
          Console.Read();
        }
      }

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 10, 2015 1:20 AM

All replies

  • User2103319870 posted

    xavier.r.fernando

    can someone please send the csharp code to convert the first string like the second one

    a.b.c

    "a"."b"."c"

    You can try with the below code

    //Your string
    string s = "a.b.c";
    //Add double quotes
    string replaced = "\""+ s.Replace(".", "\".\"")+"\"";  //This line outputs "a"."b"."c"
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 11:32 PM
  • User-434868552 posted

    @xavier.r.fer...   TIMTOWTDI

    Why would you want to?

    Do you simply mean how to code your string?

    Console.WriteLine(@"""a"".""b"".""c""");

    output:

    "a"."b"."c"

    xavier.r.fer..., some clarification from you would be helpful.

    Where is your   a.b.c    ?   in code?  in a data file?

    http://weblogs.asp.net/gerrylowry/clarity-is-important-both-in-question-and-in-answer 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 11:51 PM
  • User1271516709 posted

    Hi Xavier.r.Fernando,

    Please try below code it will work with any string that have . as separator.

     class Program
      {
        public static string test = "a.b.c";
        static void Main(string[] args)
        {
          var array = test.Split(new char[]{'.'}, StringSplitOptions.RemoveEmptyEntries);
          string result = string.Join("\".\"", array);
          result = "\"" + result + "\"";
          Console.WriteLine(result);
          Console.Read();
        }
      }

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 10, 2015 1:20 AM