【问题标题】:Is it possible to replace " (double quotes) with a white space in a string?是否可以用字符串中的空格替换“(双引号)?
【发布时间】:2014-09-07 19:59:03
【问题描述】:

在我的项目执行的某个时间点,数据库的输入格式为:

通过mycompany.com购买“xxxxxx & xxxxxx”的需求

这会导致不正确的 SQL 语法错误。我需要用空格替换"。我在谷歌搜索但没有有用的建议。

如何用空格替换"

Dim str As String
str="Buy Requirement of "Telemarketing & ERP Software" through IndiaMART.com"
' TODO: perform replace 

' result
str = "Buy Requirement of Telemarketing & ERP Software through IndiaMART.com"

【问题讨论】:

  • 您需要使用SQL patamerets:Preventing SQL Injection on ASP.NET Web Application。它是安全的(您的代码已经存在安全漏洞),并且会自动为您处理所有数据类型的转义和格式化。
  • 但是如何用空格替换 ".. 问题仍然存在
  • @SujithKarivelil - 这是个错误的问题:What is the XY problem?。 (虽然删除的答案有:str.Replace("""", "")
  • 删除的答案不是针对它被删除的问题。有问题他们要求替换 "(only one double quotes ) 但 str.Replace("""", "")) 在这种情况下不会有用 str.Replace("""", "")) 只会替换一个一对双引号
  • @Kobi 替换不起作用...

标签: sql .net vb.net asp.net-mvc-3


【解决方案1】:

我终于明白你现在在问什么了……

这里,这就是你想要使用的:teststring.Replace(""""c, "")

如果你真的想使用 Linq 和扩展方法,那么使用这个:New String(teststring.Where(Function(c) Char.IsLetterOrDigit(c) OrElse Char.IsWhiteSpace(c)).ToArray())

但这只是无缘无故地让事情变得复杂。

【讨论】:

  • 字符串中仍然保留一个引号
  • 我以为你只想替换一个双引号?
  • 每个单双引号 (")
  • 我有以下代码,但它也删除了空间Dim input As String = InputBox("ENTER") Dim output As String = New String((From c As Char In input Select c Where Char.IsLetter(c)).ToArray()) MsgBox(output)
  • 请看我的回答。我再次修改,因为我终于明白你在追求什么了。
猜你喜欢
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 2015-08-25
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
相关资源
最近更新 更多