Reputation: 2805
I am creating a string in c#.
string jsVersion = @"function getContent() {
var content = " + "\"" + documentString + "\"" + @"
return content;
}";
The documentString variable contains a huge string which have line breaks also. Now in javascript when i load this string the content variable does not contains a valid string (because of line breaks).
Now how can i create a string which is valid even if there is line breaks ?
Upvotes: 1
Views: 109
Reputation: 7906
If you want to get rid of the line breaks just remove @
from the sting.
@
acts a verbatim for your string and therefor adds the line breaks you entered with your declaration.
string jsVersion = "function getContent() {
var content = " + "\"" + documentString + "\"" + "
return content;
}";
should do the trick.
Upvotes: 0
Reputation: 8871
This will replace your line breaks with <br/>
:-
stringToDecode.replace(/\n/, '<br />')
Upvotes: 0
Reputation: 9049
Can you use string.format instead of concatenation in this fashion?
An example:
string jsVersion = string.format("function getContent() {var content = '{0}'return content; }",documentString);
Upvotes: 1