Skip to content
Advertisement

Replace [ ] bracket in a string

I have a string that includes brackets, [], around a number. Since this string represents my column names for a SQL database I need to remove/replace them. So far I do it in the following way:

It works fine, but it looks ugly for me since I have to do that for [1] to [20].

Is there a way to implement this “nicer” which means with less code for me?

Advertisement

Answer

You can use Regex.Replace to ensure to only extract the numbers:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement