0

Can somebody please tell me how can I assign following value to a string in java.

"00000000-0000-0000-0000-000000000005","00000000-0000-0000-0000-000000000001",["51371de4-622b-11e1-bb0c-002264c17b68","b607e081-5f87-11e1-a166-002264c24cf0"],[{"2154\|0\|8CEC44F365CCAD0\|\|0\|1\|0\|0\|14\|3\,11"},{"2150\|0\|8CEC1AB9F9BB9D0\|\|0\|1\|0\|0\|14\|3"}],null,{"00000000-0000-0000-0000-000000000005",null,,FirstPage,5,1,"00000000-0000-0000-0000-000000000000","",null,Date,false,false,"",null,-1,-1,false,Off,0,null,"2012-04-17T11\:45\:23.690Z",false},true,false,null,null,null,false,false,false,false

Please note that I want starting " in my string. I tried to put \ before each " which is part of the string value but that did not work. Any help would be highly appreciated !

Regards.

1
  • 4
    You say it didn't work... what happened? Please show what you tried, and the result.
    – Jon Skeet
    Apr 24, 2012 at 11:45

4 Answers 4

2

Here you go,

String escapedString =
            "\"00000000-0000-0000-0000-000000000005\",\"00000000-0000-0000-0000-000000000001\",[\"51371de4-622b-11e1-bb0c-002264c17b68\",\"b607e081-5f87-11e1-a166-002264c24cf0\"],[{\"2154\\|0\\|8CEC44F365CCAD0\\|\\|0\\|1\\|0\\|0\\|14\\|3\\,11\"},{\"2150\\|0\\|8CEC1AB9F9BB9D0\\|\\|0\\|1\\|0\\|0\\|14\\|3\"}],null,{\"00000000-0000-0000-0000-000000000005\",null,,FirstPage,5,1,\"00000000-0000-0000-0000-000000000000\",\"\",null,Date,false,false,\"\",null,-1,-1,false,Off,0,null,\"2012-04-17T11\\:45\\:23.690Z\",false},true,false,null,null,null,false,false,false,false";

Between as mentioned by Philipp Reichart please give credits to people who answer your question

2

You have a lot of reserved characters in your string - each of which will need to be exempted by putting \ before it - n.b. this includes the occurrences of "\" in your string.

I assume your problem is getting this string to compile - break it down into smaller chunks to see if there are any compilation problems in each chunk. You could then print these chunks out to the console to check they are represented as you would require.

0
String str = "\"00000000-0000-0000-0000-000000000005\",\"00000000-0000-0000-0000-000000000001\",[\"51371de4-622b-11e1-bb0c-002264c17b68\",\"b607e081-5f87-11e1-a166-002264c24cf0\"],[{\"2154\\|0\\|8CEC44F365CCAD0\\|\\|0\\|1\\|0\\|0\\|14\\|3\\,11\"},{\"2150\\|0\\|8CEC1AB9F9BB9D0\\|\\|0\\|1\\|0\\|0\\|14\\|3\"}],null,{\"00000000-0000-0000-0000-000000000005\",null,,FirstPage,5,1,\"00000000-0000-0000-0000-000000000000\",\"\",null,Date,false,false,\"\",null,-1,-1,false,Off,0,null,\"2012-04-17T11\\:45\\:23.690Z\",false},true,false,null,null,null,false,false,false,false";

replace '\' with '\\' and '"' with '\"'

0

String X="\"Hey\\""; System.out.println(X);

I got output as: "Hey\"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.