Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

AscW Equivalent

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 19 Oct 2007 20:41 GMT
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.
Nicholas Paldino [.NET/C# MVP] - 19 Oct 2007 20:54 GMT
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).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> 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.
Richard - 23 Oct 2007 21:49 GMT
Thanks Nicholas!

> Richard,
>
[quoted text clipped - 6 lines]
> > this in C#? I do not want to reference the Microsoft.VisualBasic namespace
> > for just this function.
Jon Skeet [C# MVP] - 19 Oct 2007 21:36 GMT
> 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?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Richard - 19 Oct 2007 22:57 GMT
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

> > 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
[quoted text clipped - 3 lines]
> already in Unicode. Are you trying to convert text into the default
> encoding for the platform?
Jon Skeet [C# MVP] - 19 Oct 2007 23:04 GMT
> 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;
}

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Richard - 23 Oct 2007 21:49 GMT
Thanks 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:
[quoted text clipped - 5 lines]
>     break;
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.