AscW Equivalent

G

Guest

VB has the AscW function. There is no corresponding C# function. How can I do
this in C#? I do not want to reference the Microsoft.VisualBasic namespace
for just this function.
 
N

Nicholas Paldino [.NET/C# MVP]

Richard,

You can just convert the character to an integer, and it will give you
the same thing (or, if you are talking about the version that takes a string
and not a character, use the first character in the string).
 
J

Jon Skeet [C# MVP]

Richard said:
VB has the AscW function. There is no corresponding C# function. How can I do
this in C#? I do not want to reference the Microsoft.VisualBasic namespace
for just this function.

What *exactly* do you want to do? Bear in mind that every char is
already in Unicode. Are you trying to convert text into the default
encoding for the platform?
 
G

Guest

Hi Jon,

I'm converting the Web Log Analyzer Starter Kit from VB to C#. In the
following procedure, I'm stuck on the line to convert the AscW logic below:

Public Function Parse(ByVal logFileName As String) As List(Of LogFileEntry)
' A collection representing all valid entries in the log file.
Dim logFileEntries As New List(Of LogFileEntry)

' Remember the name of the log file. This is needed later to
generate error messages.
m_logFileName = logFileName

' Read the contents of the file line by line and parse each line.
Using reader As New StreamReader(logFileName)
Do
Dim line As String = reader.ReadLine()
' If there are no more lines then exit the loop.
If (line Is Nothing) Then Exit Do

' If the first character is a 0 byte then exit the loop. This
may happen if IIS
' is still writing to the log file.
If (line.Length > 0) AndAlso (AscW(line.Chars(0)) = 0) Then
Exit Do

' If the first character is a # then this is a directive
otherwise it is an entry.
If line.StartsWith("#") Then
ParseDirective(line)
Else
Dim access As LogFileEntry = ParseLogEntry(line)
' If the line was successfully parsed add the
LogFileEntry object to a collection.
If access IsNot Nothing Then
logFileEntries.Add(access)
End If
End If
Loop
End Using

' Return the collection of LogFileEntry objects.
Return logFileEntries
End Function
 
J

Jon Skeet [C# MVP]

Richard said:
I'm converting the Web Log Analyzer Starter Kit from VB to C#. In the
following procedure, I'm stuck on the line to convert the AscW logic below:

Just check for the first character of the line being '\0'.

if (line.Length > 0 && line[0]=='\0')
{
break;
}
 
G

Guest

Thanks Jon!

Jon Skeet said:
Richard said:
I'm converting the Web Log Analyzer Starter Kit from VB to C#. In the
following procedure, I'm stuck on the line to convert the AscW logic below:

Just check for the first character of the line being '\0'.

if (line.Length > 0 && line[0]=='\0')
{
break;
}
 
G

Guest

Thanks Nicholas!

Nicholas Paldino said:
Richard,

You can just convert the character to an integer, and it will give you
the same thing (or, if you are talking about the version that takes a string
and not a character, use the first character in the string).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Richard said:
VB has the AscW function. There is no corresponding C# function. How can I
do
this in C#? I do not want to reference the Microsoft.VisualBasic namespace
for just this function.
 

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