删除字符串中的单双引号 [英] Remove a single double quote in a string

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

问题描述

大家好,

我正在使用Visual Studio2008.我将临时数据存储在包含双引号的字符串上.我应该如何删除引号?我从数组中获取数据进行存储,并且需要先将数据传输到结构中,然后再继续保存到数据库中.我从文本文件中获取数据,并使用streamreader读取数据并将其放入数组.

示例:

hi all,

I''m using visual studio 2008. I store a temp data on a string which contain double quote. How should i remove the quote?I get the data from array to store and need to transfer the data to structure before proceeding save into database. I get the data from text file and use streamreader to read the data and put into array.

Example:

strCustInfo=strArray(0) ---- "TRANSPORT "MEDIA" DEPT PVT. LTD"      ---- data appear in array with ""


是否可以删除双qoutes?
如果某些数据只有1个双引号,也可以将其删除吗?

示例:


Is it possible to remove the double qoutes?
If some data has only 1 double quote, is it also can be remove?

Example:

strCustInfo=strArray(1) ---- "SOFTMEDIA D"PT PVT. LTD"      ---- data appear in array with "


我只是假设从数据库下载时带双引号的数据是问题.


I just assume that the data with 1 double quote is problem when download from database.

推荐答案

如果您使用的是参数(请参阅: ^ ])在您的SQL语句中,引号不会在您的插入,选择等操作中引起问题.

如果用户输入了此数据,则IMO修改数据是个坏主意.应用程序应按原样存储信息.
If you''re using parameters (see: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx[^]) in your SQL statements, the quotes won''t cause problems in your insert, selects etc.

If the user has entered this data, IMO modifying the data is a bad idea. The application should store the information as it is.


此代码可以帮助您
This Code may help you
string Data = TextBox1.Text;
Data = Data.Replace("\"", "");
TextBox1.Text = Data;


想象TextBox1.Text是数据库中的数据


imagine TextBox1.Text is data from database


尝试一下:
Try This one :
Dim S As String = "Your String"
S = S.Remove("'")


希望对您有帮助. :)


I hope it will help you. :)


这篇关于删除字符串中的单双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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