C# code to VB?

R

Roshawn Dawson

Hi,

I've tried my best to convert the C# code below to it's VB equivalent.
I've even used all of the free code converters there are on the net, but
none can get this right. Here is the code:

internal static string ResolveUrl(string appPath, string url)
{
if (url.Length == 0 || url[0] != '~')
return url;// there is no ~ in the first character position, just
return the url
else
{
if (url.Length == 1)
return appPath; // there is just the ~ in the URL, return the appPath
if (url[1] == '/' || url[1] == '\\')
{
// url looks like ~/ or ~\
if (appPath.Length > 1)
return appPath + "/" + url.Substring(2);
else
return "/" + url.Substring(2);
}
else
{
// url looks like ~something
if (appPath.Length > 1)
return appPath + "/" + url.Substring(1);
else
return appPath + url.Substring(1);
}
}
}

The problem is that all of the code converters on the web treat the
"url" parameter as if it were an array, but it isn't.

Can anyone help me? I sure could use your expertise.

TIA,
Roshawn
 
M

Michael C#

Something like this? (I replaced all those 'return' statements with a
single return at the end of the function... sorry, habit...)

Friend Shared Function ResolveUrl(ByVal appPath As String, ByVal url As
String) As String
Dim Result As String = ""
If (url.Length = 0 OrElse url.Substring(0, 1) <> "~") Then
Result = url ' there is no ~ in the first character position, just
' return the url
Else
If (url.Length = 1) Then
Result = appPath ' there is just the ~ in the URL, return the
appPath
If (url.Substring(1, 1) = "/" OrElse url.Substring(0, 1) = "\") Then
' url looks like ~/ or ~\
If (appPath.Length > 1) Then
Result = Result + "/" + url.Substring(2)
Else
Result = "/" + url.Substring(2)
End If
End If
Else
' url looks like ~something
If (appPath.Length > 1) Then
Result = appPath + "/" + url.Substring(1)
Else
Result = appPath + url.Substring(1)
End If
End If
End If
Return Result
End Function
 
G

Guest

Our Instant VB C# to VB.NET converter produces:

Friend Shared Function ResolveUrl(ByVal appPath As String, ByVal url As
String) As String
If url.Length = 0 OrElse url.Chars(0) <> "~"c Then
Return url ' there is no ~ in the first character position, just return
the url
Else
If url.Length = 1 Then
Return appPath ' there is just the ~ in the URL, return the appPath
End If
If url.Chars(1) = "/"c OrElse url.Chars(1) = "\"c Then
' url looks like ~/ or ~\
If appPath.Length > 1 Then
Return appPath & "/" & url.Substring(2)
Else
Return "/" & url.Substring(2)
End If
Else
' url looks like ~something
If appPath.Length > 1 Then
Return appPath & "/" & url.Substring(1)
Else
Return appPath & url.Substring(1)
End If
End If
End If
End Function

Note that this is produced with our free demo edition (www.instantvb.com)
and it does not treat url as an array.

Regards,
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top