Replace whitespace outside quotes using regular expression

前端 未结 5 857
天涯浪人
天涯浪人 2020-12-11 20:05

Using C#, I need to prepare a search text for searching in a SQL Server database using the LIKE command by replacing all whitespace outside quotes with a % character. Exampl

5条回答
  •  被撕碎了的回忆
    2020-12-11 20:22

    Instead of using a RegEx, use a simple state machine - loop over each character, noting whether you are "in" or "out" of quotes and only replace spaces when you are in the "out" state.

提交回复
热议问题