5

Replace \\ n with \ n in a string in C #

 3 years ago
source link: https://www.codesd.com/item/replace-n-with-n-in-a-string-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Replace \\ n with \ n in a string in C #

advertisements

I have a string

var string = "I have a a string \\nThis is a new line\\nThis is another";

what I want is

var string = "I have a a string \nThis is a new line\nThis is another";

I have used

string.Replace("\\","\");
Newline in constant

But get the error message "Newline in constant"


What you really want to replace is a backslash followed by the letter n with the newline character

string.Replace("\\n","\n");

The reason Replace("\\","\") gives that compilation error is because the backslash is escaping the double quote so the string continues on to the end of the line which is not allowed unless it's a verbatim string (starts with an @).

Tags string

Related Articles

Replacing symbols with spaces in a string

I'm writing a program that can format text files of thousands of lines of data. The input text file are lines such as: 2010-01-01 00:00:00 0.520368 0.558565 0.567376 What I want to do is replace the dashes and ':' with spaces, and then put proper tab

replace escape "with escape" in ruby ​​string

I have a ruby string which includes many escaped double quotes \" that I want to replace with an escaped single quote \' but I can't work out how to do it. I've been trying to use gsub, but something like mystring.gsub('\\"', '\\'') doesn't work

Python: Replacing integers with floats in a string

I'm looking for a way, to replace every number inside a string by a float number. So I'd turn this: "3/1" to this: "3.0/1.0" Is there a way to do this?You can use re.sub : >>> s="3/1" >>> import re >>&

Regular expression to replace spaces with dashes in a substring.

I've been struggling to find a way to replace spaces with dashes in a string but only spaces that are within a particular part of the string. Source: ABC *This is a sub string* DEF My attempt at a regular expression: /\s/g If I use the regular expres

Replace \ delete the character in the string

string DelStr = "I! am! bored!"; string RepStr = "10/07/10" I want to delete all '!' on DelStr and I want to replace all '/' with '-' on the RepStr string. Is there any way to do this without doing a loop to go through each character?R

Replace all \ with a string with / using javascript

I am currently working on Javascript. I have a variable withich take value D:\Abc\xyz\mno\rst\uvw.inc I need to replace all \ with / from above variable. I am getting the error: SyntaxError: unterminated string literal Can someone please help me with

PHP string replacement operations with DB in consideration

I want to do some replacement type of operations on my string in PHP using DB. For example: $inputString = "My name is [[name-abc]] and age [[age-25]]"; And I have DB table as follow: id input output 1 name-abc LINK_TO_ABC_PROFILE 2 name-def LIN

Replacing Javascript with *, + and / characters in a string

Alright, so I'm currently working on a simplistic manner of mimicking the function of PHP's urlencode() with JS's escape() and some string replacement. I'm purely looking at keyboard characters, so no special ASCII or Unicode characters. The problem

How can I replace a special character in a string with underscores using a Perl script?

I have a script taking mythtv recorded shows and encoding them in h264 using handbrake. the script is written in Perl. My questions is how do I replace spaces and special characters with and underscore using perl? The strings look something like this

Notepad ++ Regex (Using Find & Replace) I want to locate a specific word and replace it with a string that appears between two different tags

Here's what I'm looking to do with the following code: ;"0";"<br>Address: 999 Murrica Avenue Washington D.C.<br>Contact:";"";"";"LAYER";"4";"AHA";"925";"px&qu

The original string contains & ldquo; +, the regular expression extractor (. +?) replaces it with a space. How do I extract with the & ldquo; + & Rdquo;

(Edit: The answer is to use check 'Encode?'option in the HTTP Request. Please see Vinoth's Edit 2 and comment below, thanks!) This is interesting! I'm trying to parse a HTTP response which has (let's give concrete example, bigH:"2a3a6CEH+iJakQpQtPm8e

Find a special string in a text and replace it with content from the table

Consider this text $text = 'bla bla bla bla (=abc) bla bla bla bla (=var.var)'; There are 2 special values there (=abc) and (=var.var) I need to replace them with values from this array: $array['abc']='word1'; $array['var.var']='word2'; Basically ins

How to replace the last character of a string with VB6?

How do I replace the last character in a string with VB6? I've got the syntax Replace$(expression, find, replacewith[, start[, count[, compare]]]) but I can't seem to find the right use of it. I've got something like iLength = Len(sBuild) sBuild = Re

MYSQL Replace the string array with a randomly selected string set

I have a users table with a user_email field. I'd like to replace all user emails that match: *@a.com *@b.com *@c.com With a randomly chosen string from d.com e.com f.com g.com Example: Before: -------------------------------------- |user_name | user
HashFlare

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK