Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
String s=" I am Abc";

I have to replace Abc with "Abc"

output should be like I am "Abc"
but I am getting error newline constant

What I have tried:

s = s.Replace("Abc", "\"Abc");
Posted
Updated 25-Jun-19 21:39pm

String s = " I am Abc";
     s = s.Replace("Abc", "\"Abc\"");


to understand:
string quotes = "\"";
       String s = " I am Abc";
       s = s.Replace("Abc", quotes +"Abc" +  quotes);
 
Share this answer
 
v2
Comments
Pragya Nagwanshi 14-Mar-17 2:24am    
Thankuuuuuuuuuuuu so much. I succed
Karthik_Mahalingam 14-Mar-17 2:25am    
welcome
Pragya Nagwanshi 14-Mar-17 2:29am    
Ok again one problem
string s="I am "Abc"";
output should be like I am "PQR"";
Please help me naa
Karthik_Mahalingam 14-Mar-17 2:30am    
  string quotes = "\"";
        String s = " I am Abc";
        s = s.Replace("Abc", quotes +"PQR" +  quotes + quotes); 
Pragya Nagwanshi 14-Mar-17 2:33am    
Big Thanks.Genius you are
//Your code goes here
String s=" I am Abc";
s = s.Replace("Abc", "\"Abc\"");
Console.WriteLine(s);
 
Share this answer
 
Comments
CHill60 26-Jun-19 4:11am    
This is exactly the same as Solution 1 from over 2 years ago. Don't just copy other member's answers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900