Q:

How to find if the VB string variable has the vbTab and replace with underscores or some other characters

How to find whether the given VB.Net string has the vbCrLf, vbTab and other built in constants then replace them with some other characters like underscore or hyphen etc. I am stuck on the below code for some time and could not get to figure out why it is not replaced.
       Dim msg As String
       msg = "Hello I am test message" & vbTab & vbTab & " After two tabs " & vbCrLf & "I am in next line"
       msg = msg.Replace("vbTab", "____")
       msg = msg.Replace("&vbTab&", "****")
       MessageBox.Show(msg)

OUTPUT: I get tab instead of  underscore or asterich.

A:

Your problem is that you are trying to replace a literal string of 5 characters "vbTab" rather than the Tab character.
Remove the quotes around vbTab in your Replace function and you will get the underscores in your output
 Dim msg As String
 msg = "Hello I am test message" & vbTab & vbTab & " After two tabs " & vbCrLf & "I am in next line"
 msg = msg.Replace(vbTab, "____")
 ''msg = msg.Replace("&vbTab&", "****")  No idea how to fix this as it will never match anything
 MessageBox.Show(msg)

I don't know what you're trying to achieve with your second Replace as this seems to be trying to replace a tab character surrounded by two concatenation operators. The concatenation operators will never be in the string, and after the first Replace is executed, there wouldn't be any vbTabs remaining anyway.

