Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String.Replace() method doesn't work - what am I doing wrong? 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,

I am writing code for a procedure which receives 2 arguments/parameters: tcFileIn, tcFileOut, both As String,
e.g.
Code:
Sub Read_Write_XML(ByVal tcFileIn As String, Optional ByVal tcFileOut As String = "")

In the parameters' verification section, I have the following code:

Code:
If tcFileOut = "" Then
   tcFileOut = tcFileIn.Replace(".XML", "_Out.XML")
End If

When I test it in VS 2012 IDE with 2nd parameter absent

Code:
Read_Write_XML(sDataDir & "InputFile.xml")

- it shows the tcFileOut is the same as the tcFileIn.
Step-by-step run showed that it does enter into the If-End If construct and executes this line with String.Replace() but... see above.
IOW, tcFileIn.Replace() doesn't work the way I expect.

What am I doing wrong?

Please advise!

TIA!

Regards,

Ilya
 
20200225_String_Replace_Malfunction_zbxwzp.jpg


Regards,

Ilya
 


Your string comparison is not taking the case of the input string into consideration. "nputFile.[red]xml[/red] passed as a parameter will not be found when trying to compare to [red]XML[/red]

You'll need to uppercase the tcfilein extension to match the compare.


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
That's it! Thank you Mark!
(Me's gettin' older... What's that 1st thing to go before the eyesight? :-( )

Regards,

Ilya
 
(Usually....) Your hair [hairpull]
[lol]


---- Andy

There is a great need for a sarcasm font.
 
Respectfully disagree, Mr. Andrzejek!
My hair ain't not yet gone! ;-)

Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top