I have sql strings such as the following, with several Trues
and Falses
:
INSERT INTO SystemRules (Col1, Col2, Col3, Col4, Col5)
Values (False,False,True,False,False)
I want to replace all False with 0 and all True with 1. But when I try this:
sql = sql.Replace(",True,", ",1,").Replace(",True)", ",1)").Replace(",False,", ",0,").Replace(",False)", ",0)");
...it only removes some of the Falses...not all of them. For example, I end up with this:
INSERT INTO SystemRules (Col1, Col2, Col3, Col4, Col5)
Values (0,False,1,0,False)
What I expected was this:
INSERT INTO SystemRules (Col1, Col2, Col3, Col4, Col5)
Values (0,0,1,0,0)
So then I try regex instead (showing just 1 piece below):
sql = Regex.Replace(sql, ",True)", ",1)");
That particular line blows up with this error: parsing ",True)" - Too many )'s.
What is the most efficient way to replace all Trues and Falses in a sql statement with 1s and 0s? I have always found string.Replace() in c# to replace globally, I'm baffled as to why it's missing some. There are no spaces in there, I have triple-checked. One proof of this is that if I run the series of REPLACEs above a 2nd time, it does replace the stragglers. Why not the first time? Is c# replace
really not global? Thank you.