开发者

Precise String.Split

开发者 https://www.devze.com 2023-03-09 16:30 出处:网络
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

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?

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' value to be inserted into my table row. 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...

Edit: Everybody has the same sentiments. Thanks guys, it worked. I think I should开发者_StackOverflow just make a better delimiter for this too. XD


I dont think so something like that is available

but you can try "RegularExpression" not sure but may resolve your issue.


Try using Regex.Split where you can define a pattern to split.

Update: You can start with Regex: "([^;]*?('.*?')?)*?;\\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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号