RE: Newbie question on string operators in C#
- From: David Anton <DavidAnton@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 1 Apr 2008 08:07:01 -0700
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
- Follow-Ups:
- RE: Newbie question on string operators in C#
- From: David Anton
- RE: Newbie question on string operators in C#
- References:
- Newbie question on string operators in C#
- From: Richard
- Newbie question on string operators in C#
- Prev by Date: Re: textbook authors: passing by ref is NOT more efficient!
- Next by Date: Re: textbook authors: passing by ref is NOT more efficient!
- Previous by thread: Re: Newbie question on string operators in C#
- Next by thread: RE: Newbie question on string operators in C#
- Index(es):
Relevant Pages
|
Loading