更换 [英] replace

查看:81
本文介绍了更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个字符串:


string c ="''abc''\" cde \\ \\,''mno''\" xyz \"," ;;


如何使用c.Replace(???,??? )方法有这个字符串:


"''abc''" cde",''mno''" xyz","

即,所有的反斜杠都被移除。


谢谢,


Etu

Hi,

I have a string:

string c = "''abc'' \"cde\", ''mno'' \"xyz\",";

how can I use the c.Replace(???, ???) method to have this string:

"''abc'' "cde", ''mno'' "xyz","
that is, all the backslashes are removed.

Thanks,

Etu

推荐答案

在您编写的代码行中:

string c ="''abc''\" cde \" ;''mno''\" xyz \"," ;;


字符串中没有反斜杠。你看到的反斜杠是

只是一个印刷约定告诉编译器每个反斜杠后面的

双引号不是双引号

结束字符串,但它应该在字符串中放置一个双引号

字符。


编译后内部存储的字符串看起来像这个:


''abc''" cde",''mno''" xyz",


你在试什么在你的程序中做什么以及你遇到什么问题,因为字符串中的反斜杠看起来不像是'b $ b'错误了什么?

In the line of code you wrote:

string c = "''abc'' \"cde\", ''mno'' \"xyz\",";

there are no backslashes in the string. The backslashes you see are
only a typographical convention that tells the compiler that the
double-quote that follows each backslash is not the double-quote that
ends the string, but that it should instead place a double-quote
character in the string.

The string stored internally after compilation looks like this:

''abc'' "cde", ''mno'' "xyz",

What are you trying to do in your program and what problems are you
encountering, since backslashes in the string don''t appear to be what''s
wrong?


string c ="''abc''\" cde \",''mno''\" xyz \", " ;;

string clearString = c.Replace(''\\'',''''); //你必须输入反斜杠两次


这就是全部


希望这有助于


Etu <等***** @ yahoo.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
string c = "''abc'' \"cde\", ''mno'' \"xyz\",";
string clearString = c.Replace(''\\'', '' ''); // You must type backslash twice

That''s All

Hopes This Helps

"Etu" <et*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...


我有一个字符串:

string c ="''abc''\"'cde \",''mno ''\'" xyz \"," ;;

如何使用c.Replace(???,???)方法获取此字符串:

"''abc''" cde",''mno''" xyz","
即所有反斜杠都被移除。

谢谢,

Etu
Hi,

I have a string:

string c = "''abc'' \"cde\", ''mno'' \"xyz\",";

how can I use the c.Replace(???, ???) method to have this string:

"''abc'' "cde", ''mno'' "xyz","
that is, all the backslashes are removed.

Thanks,

Etu



谢谢布鲁斯!


实际上我遇到的问题是我的程序首先从XML文件中读取一些字符串

(带\t,\"等等),然后将这些字符串写入

Excel文件。保存Excel文件后,\t成为一个空格,\"

变为。然后,当我的程序稍后从Excel

文件中读取字符串时,它不认为字符串与XML

文件中的字符串相同。


这就是为什么我试图通过

去掉反斜杠来修改XML文件中的字符串 - 尝试做同样的事情来实现Excel

确实如此,但找不到办法。


谢谢


布鲁斯伍德写道:
Thanks Bruce!

The problem I have is actually my program first reads some strings
(with \t, \" and so on) from an XML file and writes these strings to an
Excel file. After the Excel file is saved, \t becomes a space and \"
becomes ". Then when my program later reads the strings from the Excel
file, it doesn''t think the strings are the same as those in the XML
file.

That is why I was trying to modify the strings from the XML file by
getting rid of the backslashes - try to do the same thing that Excel
does, but could not find a way to do so.

Thanks

Bruce Wood wrote:
在您编写的代码行中:

string c ="''abc''\" cde \",''mno''\" xyz \\ \\," ;;

字符串中没有反斜杠。你看到的反斜杠只是一个印刷约定,告诉编译器每个反斜杠后面的双引号不是
结束字符串的双引号,而是应该改为在字符串中放置双引号
字符。

编译后内部存储的字符串如下所示:

''abc''" cde", ''mno''" xyz",

在你的程序中你想做什么以及你遇到什么问题,因为字符串中的反斜杠似乎不是
出了什么问题?
In the line of code you wrote:

string c = "''abc'' \"cde\", ''mno'' \"xyz\",";

there are no backslashes in the string. The backslashes you see are
only a typographical convention that tells the compiler that the
double-quote that follows each backslash is not the double-quote that
ends the string, but that it should instead place a double-quote
character in the string.

The string stored internally after compilation looks like this:

''abc'' "cde", ''mno'' "xyz",

What are you trying to do in your program and what problems are you
encountering, since backslashes in the string don''t appear to be what''s wrong?






这篇关于更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆