none
VB: Not sure why the Replace method won't replace my text? RRS feed

  • Question

  • When our process identifies an incorrect hyperlink file path, I'm trying to identify the wrong substring and replace it with the correct substring, but it is not working. I'm sure I'm missing something stupid.  The hyperlink is a passed argument to an exe and I call to it using cmdArgs(0) from the sub Main. I then convert it to a string. But then I run into the issue I stated.

            Dim str As String = "http://directsit.mysite.net/myfolder/myscript.vbe"
    
            If str.ToLower.Contains("directsit") Then
                str.ToLower.Replace("directsit", "directprod")
    
            End If
            Console.WriteLine(str)
            Console.ReadLine()


    SV

    Wednesday, September 27, 2017 1:56 PM

Answers

  • When our process identifies an incorrect hyperlink file path, I'm trying to identify the wrong substring and replace it with the correct substring, but it is not working. I'm sure I'm missing something stupid.  The hyperlink is a passed argument to an exe and I call to it using cmdArgs(0) from the sub Main. I then convert it to a string. But then I run into the issue I stated.

            Dim str As String = "http://directsit.mysite.net/myfolder/myscript.vbe"
    
            If str.ToLower.Contains("directsit") Then
                str.ToLower.Replace("directsit", "directprod")
    
            End If
            Console.WriteLine(str)
            Console.ReadLine()


    SV

    Hi

    Try this - you need to set the variable to the new value.

            Dim str As String = "http://directsit.mysite.net/myfolder/myscript.vbe"
    
            If str.ToLower.Contains("directsit") Then
                str = str.ToLower.Replace("directsit", "directprod")
    
            End If
            Console.WriteLine(str)
            Console.ReadLine()


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, September 27, 2017 2:05 PM
    • Proposed as answer by Frank L. Smith Wednesday, September 27, 2017 2:47 PM
    • Marked as answer by svMSDN Friday, December 1, 2017 3:48 PM
    Wednesday, September 27, 2017 2:05 PM