Tutorial :How to use replace when making one variable = two others instead of just one


Okay this one might be a little tougher. I'm using VB that looks like this:

string = Replace(string.ToLower, chr(63), "A")  

But I also want chr(63) = "B" as well, like this:

string = Replace(string.ToLower, chr(63), "B")  

My problem is that when chr(63) is at the end of a string I need it to be B, and when it's not the end I need it to be A. I suppose that I can use an if/then/else statement. Is there a way to do this?


XXXXXchr(63)XXXXX = A  


XXXXXXXXXXchr(63) = B  



pseudo:  if (string[string.Length] == chr(63))  {     string[string.Length] = B  }  string = Replace(string.ToLower, chr(63), "A")  


string = Replace(string.ToLower, chr(63), "A", 1, Len(string) - 1)  If Right(string, 1) = chr(63) then     Mid$(string, Len(string), 1) = 'B'  End if  

Update: in response to comment:


I haven't used Visual Basic since version 6, but it should be something like this:

If Robert.EndsWith(chr(63)) Then      Robert = Left(Robert, Robert.Length - 1) + "B"  End If  

Then do the usual replacement with A.


This ought to do it

    Dim s As String       Dim char63 As String = Convert.ToChar(63).ToString      If s.EndsWith(char63) Then          s = s.Substring(0, s.Length - 1) & "B"      End If      s = s.Replace(char63, "A")  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »