[英]Precise String.Split
I have a file that contains SQL statements that is delimited by semicolons, is there a way to make sure that strings in my file that have semicolons inside values to be inserted won't be affected by String.Split?我有一个文件,其中包含用分号分隔的 SQL 语句,有没有办法确保我的文件中的字符串在要插入的值中包含分号不会受到 String.Split 的影响?
Example:例子:
Insert Into items(Description) Values('Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V');
Insert Into items(Description) Values('SSA 215');
I want to the whole 'Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V'
我想要整个
'Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V'
'Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V'
value to be inserted into my table row. 'Anti Surge T; LBC Slow Blow 6.3 x 32mm 7A / 250V'
值要插入我的表格行。 But since I using <sql_statemet>.Split(new char { ';' })
the sql statement is not complete since there's a semicolon inside Anti Surge T; LBC...
但是由于我使用
<sql_statemet>.Split(new char { ';' })
,因此 sql 语句不完整,因为Anti Surge T; LBC...
Anti Surge T; LBC...
Edit: Everybody has the same sentiments.
编辑:每个人都有相同的情绪。 Thanks guys, it worked.
谢谢各位,成功了。 I think I should just make a better delimiter for this too.
我想我也应该为此做一个更好的分隔符。 XD
XD
I dont think so something like that is available我不认为这样的东西是可用的
but you can try " RegularExpression
" not sure but may resolve your issue.但您可以尝试“
RegularExpression
”不确定,但可能会解决您的问题。
Try using Regex.Split
where you can define a pattern to split.尝试使用
Regex.Split
,您可以在其中定义要拆分的模式。
Update: You can start with Regex: "([^;]*?('.*?')?)*?;\\s*"
更新:您可以从正则表达式开始:
"([^;]*?('.*?')?)*?;\\s*"
If you want to split depending on more than just a single character / string you should use如果您想拆分的不仅仅是一个字符/字符串,您应该使用
Regex.Split
there you can define the valid expression very precise在那里您可以非常精确地定义有效表达式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.