Search code examples
asp.netregexvb.netstring-search

Find and Replace a character in a string in VB.NET


I have a certain input string in this form: "[3] [4] at [5]"

From the following datatable, I need to replace the text on the datatable corresponding to the column index inside the bracket.

enter image description here

The output should be: "15A Circuit Breaker #348901836 at 19-Afalcon St. Capitol Subdivision"

Right now, I am using Regex.Replace() method but it searches for a particular pattern. My problem is the integers (corresponding the column index) enclosed inside the brackets is dynamic.

What would be the best way to achieve this?


Solution

  • String.Format should do it for you. Both the format string and the arguments can be easily implemented dynamically.

    https://msdn.microsoft.com/en-us/library/system.string.format.aspx

    All of the syntax, and a decent example of what you wish to do are on the linked page.