RE: Newbie question on string operators in C#



In VB, that would be:
If s(i) >= "A"c AndAlso s(i) <= "Z"c Then
fs(k) = 10 + CInt(Fix(s(i) - AscW("A"c)))
k += 1
End If

Unlike VB, in C# 'character math' is possible (but not very common). In C#
characters have this dual nature - what your intuition says characters are in
addition to the underlying numeric value.

--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Java to VB & C#
Instant C#: convert VB to C#
Instant VB: convert C# to VB
Instant C++: VB, C#, or Java to C++/CLI


"Richard" wrote:

Can anyone help a VB programmer understand the following C# code snippet
please? This is excerpted from a base conversion function that converts s (a
string representing a number in any base 2 to 36) into a string representing
the number in another base.

if (s[i] >= 'A' && s[i] <= 'Z') { fs[k++] = 10 + (int)(s[i] - 'A'); }

si[i] is simply a character in a string passed to the function.

fs, according to the author, is an "array of integer digits representing the
number in base:from".

What I don't understand is .... (int) (s[i] - 'A') , since both s[i] and A
are characters.

If, say, s[i] evaluates to 'F', then how does C# treat (int) ('F' - 'A')?
Does it simply convert the two characters into their ASCII numbers, thereby
evaluating it to 5?

TIA



.



Relevant Pages

  • Re: Newbie question on string operators in C#
    ... This is excerpted from a base conversion function that converts s (a ... string representing a number in any base 2 to 36) into a string representing ... Does it simply convert the two characters into their ASCII numbers, ... In fact, the (int) ...
    (microsoft.public.dotnet.languages.csharp)
  • Newbie question on string operators in C#
    ... Can anyone help a VB programmer understand the following C# code snippet ... This is excerpted from a base conversion function that converts s (a ... string representing a number in any base 2 to 36) into a string representing ... Does it simply convert the two characters into their ASCII numbers, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Newbie question on string operators in C#
    ... C++ to Java ... characters have this dual nature - what your intuition says characters are in ... This is excerpted from a base conversion function that converts s (a ... string representing a number in any base 2 to 36) into a string representing ...
    (microsoft.public.dotnet.languages.csharp)
  • Javac-compilor error
    ... discipline id.e.programming Java. ... from standard input and writes to standard output, but it is possible to redirect the input ... error occurs while trying to open the file, an exception of type IllegalArgumentException ... then this number of characters, then extra spaces are added to the front of x to bring ...
    (Fedora)
  • Re: gotchas.html: Missing Hex
    ... >> There is a difference between entering characters into ... existence of Java than the amount of words in the JLS and VMS (VM ... The problem with Java is that it is, in fact, a necessary restriction ... Java is a strongly typed language, ...
    (comp.lang.java.help)

Loading