与字符串中的双引号有关的问题(转义序列) [英] Issue related to double quotes in a string(escape sequence)

查看:94
本文介绍了与字符串中的双引号有关的问题(转义序列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中存储了各种项目条目,即ItemName,例如
abc 8"x12",xyz 4"
我已经把Radcombobox中的所有物品都拿走了,但是每当我想要selectIndex时,它就会显示
\在ItemName的每个selectedValue中的现有"(即ItemName中的英寸)之前添加,因为我无法获得该项目的selectindex.
所以我的问题是添加到ItemName(\)的内容是什么,以及如何从selectedValue中删除该\"以获取其selectedIndex
这是我的短代码,

In a Database i''ve stored various item entries ie. ItemName such as
abc 8"x12", xyz 4"
i''ve taken all the items in Radcombobox, but whenever i want the selectIndex it shows
\" added before existing " (ie. Inch in ItemName)in each selectedvalue of an ItemName, coz of that i cant get the selectindex of that item.
so my question is what is that being added to the ItemName(\") and how to remove that \" from the selectedValue to get its selectedIndex
here is my short code,

RadComboBox comboBox = (RadComboBox)editItem[dtBoundColumn.ColumnName].Controls[0];
                string selectValue = comboBox.SelectedValue;
                //selectValue.Replace("\"", "");

comboBox.SelectedIndex = comboBox.FindItemByText(selectValue).Index;


我尝试了评论部分,但没有成功.


I tried commented part but it didnt work.
thanks in advance.

推荐答案

你好:)

首先,请记住指定应用程序的类型(Web/Windows).有时,在找出问题并提供解决方案时非常方便.

好的,在C#中,下面列出了一些基本知识:
1.字符串总是用双引号引起来
2.在C#中将单个反斜杠用作转义符
3.为了表示包含双引号或单引号的字符串,您必须在每个这些字符之前加上一个单反斜杠
4.但是,当显示在屏幕上时,.Net不会显示这些反斜杠

如果您了解这些基础知识,就会了解到您无法删除用作转义符的反斜杠.

因此,请尝试这些步骤并查看;
1.创建一个带有radcombobox的测试页/窗口
2.将一些带有双引号字符的随机硬编码值放入其中
3.选择一个值并编写逻辑以用反斜杠和反斜杠搜索该值的控件

其中之一应该起作用,如果不起作用,则发布代码,以便我们可以看到您在做什么.

希望对您有所帮助
Hello there :)

First of all, please, remember to specify what type of an application it is (web/windows). Sometimes it comes very handy in both figuring out your problem and providing a solution.

Okay, in C#, there are few basics I''ve listed below:
1. Strings are always represented within double quotes
2. A single Backslash is used as the escape character in C#
3. In order to represent a string which contains double quotes or single quotes, you have to precede each of these characters with a single back slash
4. But when displayed on screen, .Net does NOT show these back slashes

If you understand these fundamentals, you''ll understand that you cannot remove backslashes that are used as escape characters from a string.

Therefore, try these steps and see;
1. Create a test page/window with a radcombobox in it
2. Put some random hard coded values with double quotes characters in it
3. Pick a value and write logic to search the control with and with back slashes for that value

One of it should work, if it doesn''t, post the code so we can see what you are doing.

Hope this helps, regards


这篇关于与字符串中的双引号有关的问题(转义序列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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