I got a String which could be : C:\Users\info\Desktop\Folder in which case I want to replace the Part of the URL after \Users\ ..\ with %Username%.
So far I manage to replace the string when i know the part before the Username, in this case Users\ and the part after the Username. But i can't manage to define \ as the end because it thinks that Users \ is the end of string to replace.
So how can i change the dim SDelimEnd so it just gives back the Username
Public Class Form1
Private Sub RadButton_Click(sender As Object, e As EventArgs) Handles RadButton.Click
Dim sSource As String = txt1.text 'String that is being searched
Dim sDelimStart As String = "Users" 'First delimiting word
Dim sDelimEnd As String = "AppData" 'Second delimiting word
Dim nIndexStart As Integer = sSource.IndexOf(sDelimStart) 'Find the first occurrence of f1
Dim nIndexEnd As Integer = sSource.IndexOf(sDelimEnd) 'Find the first occurrence of f2
If nIndexStart > -1 AndAlso nIndexEnd > -1 Then '-1 means the word was not found.
Dim res As String = Strings.Mid(sSource, nIndexStart + sDelimStart.Length + 1, nIndexEnd - nIndexStart - sDelimStart.Length) 'Crop the text between
MessageBox.Show(res) 'Display
Strings.Replace(sSource,res,"\%username%\")
MessageBox.Show(Strings.Replace(sSource,res,"\%username%\"))
txt2.Text = Strings.Replace(sSource,res,"\%username%\")
Else
MessageBox.Show("One or both of the delimiting words were not found!")
End If
End Sub
End Class