Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > getting the character code of a character in a string

Reply
Thread Tools

getting the character code of a character in a string

 
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
I'm trying to convert some JavaScript to C# and don't know how to get the
character code of a character in a string. in JavaScript it is as follows:

for( i = 0; i < email.length; i++)

{

var fs = email.charCodeAt(i);

uniemail = uniemail + '&#' + fs + ';';

}

What function would replace the .charCodeAt() function?
Thanks in advance!
Velvet


 
Reply With Quote
 
 
 
 
S. Justin Gengo [MCP]
Guest
Posts: n/a
 
      01-18-2006
Velvet,

System.Convert.ToChar("V")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Velvet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to convert some JavaScript to C# and don't know how to get the
> character code of a character in a string. in JavaScript it is as
> follows:
>
> for( i = 0; i < email.length; i++)
>
> {
>
> var fs = email.charCodeAt(i);
>
> uniemail = uniemail + '&#' + fs + ';';
>
> }
>
> What function would replace the .charCodeAt() function?
> Thanks in advance!
> Velvet
>



 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      01-18-2006
(Int32)email[i];

"Velvet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to convert some JavaScript to C# and don't know how to get the
> character code of a character in a string. in JavaScript it is as
> follows:
>
> for( i = 0; i < email.length; i++)
>
> {
>
> var fs = email.charCodeAt(i);
>
> uniemail = uniemail + '&#' + fs + ';';
>
> }
>
> What function would replace the .charCodeAt() function?
> Thanks in advance!
> Velvet
>



 
Reply With Quote
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
No, maybe I wasn't clear...

I need the Unicode character number (character code) and not just to convert
it to a character type.

Anyone else?
Andrea


"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:%(E-Mail Removed)...
> Velvet,
>
> System.Convert.ToChar("V")
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "Velvet" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I'm trying to convert some JavaScript to C# and don't know how to get the
>> character code of a character in a string. in JavaScript it is as
>> follows:
>>
>> for( i = 0; i < email.length; i++)
>>
>> {
>>
>> var fs = email.charCodeAt(i);
>>
>> uniemail = uniemail + '&#' + fs + ';';
>>
>> }
>>
>> What function would replace the .charCodeAt() function?
>> Thanks in advance!
>> Velvet
>>

>
>



 
Reply With Quote
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
This doesn't work... won't even compile.

sorry...


"Winista" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (Int32)email[i];
>
> "Velvet" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I'm trying to convert some JavaScript to C# and don't know how to get the
>> character code of a character in a string. in JavaScript it is as
>> follows:
>>
>> for( i = 0; i < email.length; i++)
>>
>> {
>>
>> var fs = email.charCodeAt(i);
>>
>> uniemail = uniemail + '&#' + fs + ';';
>>
>> }
>>
>> What function would replace the .charCodeAt() function?
>> Thanks in advance!
>> Velvet
>>

>
>



 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      01-18-2006
byte[] emailBuff = Encoding.ASCII.GetBtyes(email);
for( i = 0; i < emailBuff.length; i++)
{
int char = (int) emailBuff[i];
uniemail += string.format("&#{0};",char);
}

-- bruce (sqlwork.com)

"Velvet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to convert some JavaScript to C# and don't know how to get the
> character code of a character in a string. in JavaScript it is as
> follows:
>
> for( i = 0; i < email.length; i++)
>
> {
>
> var fs = email.charCodeAt(i);
>
> uniemail = uniemail + '&#' + fs + ';';
>
> }
>
> What function would replace the .charCodeAt() function?
> Thanks in advance!
> Velvet
>



 
Reply With Quote
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
My mistake... case sensitivity got me. Looks like this is working!
THANKS!

Velvet


"Velvet" <(E-Mail Removed)> wrote in message
news:uj15%(E-Mail Removed)...
> This doesn't work... won't even compile.
>
> sorry...
>
>
> "Winista" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> (Int32)email[i];
>>
>> "Velvet" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> I'm trying to convert some JavaScript to C# and don't know how to get
>>> the character code of a character in a string. in JavaScript it is as
>>> follows:
>>>
>>> for( i = 0; i < email.length; i++)
>>>
>>> {
>>>
>>> var fs = email.charCodeAt(i);
>>>
>>> uniemail = uniemail + '&#' + fs + ';';
>>>
>>> }
>>>
>>> What function would replace the .charCodeAt() function?
>>> Thanks in advance!
>>> Velvet
>>>

>>
>>

>
>



 
Reply With Quote
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
OK, one more problem!

The encoding happens, but when I write it to the Text property of the
Hyperlink control, it seems that ASP.NET auto converts it back to a normal
string. What is going on here? How am I supposed to keep my email
addresses from being picked up by robots if my encoding is converted back to
a normal string??

Very frustrating!
Velvet

PS: Here's the working Encoding code
public static string UniEncode(string text)

{

System.Text.StringBuilder sb = new System.Text.StringBuilder();

int charCode;


for( int i = 0; i < text.Length; i++)

{

charCode = (Int32) text[i];

sb.Append(String.Format("&#{0};",charCode));

}


return sb.ToString();

}




"Velvet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to convert some JavaScript to C# and don't know how to get the
> character code of a character in a string. in JavaScript it is as
> follows:
>
> for( i = 0; i < email.length; i++)
>
> {
>
> var fs = email.charCodeAt(i);
>
> uniemail = uniemail + '&#' + fs + ';';
>
> }
>
> What function would replace the .charCodeAt() function?
> Thanks in advance!
> Velvet
>



 
Reply With Quote
 
Velvet
Guest
Posts: n/a
 
      01-18-2006
nevermind... it seems that when you save the page from the browser that is
when the transformation happens.

Now if my 'View Source' worked.... I had to view the source in FireFox to
figure this out. For some unknown reason the 'View Source' in my IE browser
has quit working so I was saving the page to view the source.

Velvet

"Velvet" <(E-Mail Removed)> wrote in message
news:%23kzl$(E-Mail Removed)...
> OK, one more problem!
>
> The encoding happens, but when I write it to the Text property of the
> Hyperlink control, it seems that ASP.NET auto converts it back to a normal
> string. What is going on here? How am I supposed to keep my email
> addresses from being picked up by robots if my encoding is converted back
> to a normal string??
>
> Very frustrating!
> Velvet
>
> PS: Here's the working Encoding code
> public static string UniEncode(string text)
>
> {
>
> System.Text.StringBuilder sb = new System.Text.StringBuilder();
>
> int charCode;
>
>
> for( int i = 0; i < text.Length; i++)
>
> {
>
> charCode = (Int32) text[i];
>
> sb.Append(String.Format("&#{0};",charCode));
>
> }
>
>
> return sb.ToString();
>
> }
>
>
>
>
> "Velvet" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I'm trying to convert some JavaScript to C# and don't know how to get the
>> character code of a character in a string. in JavaScript it is as
>> follows:
>>
>> for( i = 0; i < email.length; i++)
>>
>> {
>>
>> var fs = email.charCodeAt(i);
>>
>> uniemail = uniemail + '&#' + fs + ';';
>>
>> }
>>
>> What function would replace the .charCodeAt() function?
>> Thanks in advance!
>> Velvet
>>

>
>



 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      01-19-2006
Hello Velvet,

> OK, one more problem!
>
> The encoding happens, but when I write it to the Text property of the
> Hyperlink control, it seems that ASP.NET auto converts it back to a
> normal string. What is going on here? How am I supposed to keep my
> email addresses from being picked up by robots if my encoding is
> converted back to a normal string??
>
> Very frustrating!
> Velvet
> PS: Here's the working Encoding code
> public static string UniEncode(string text)
> {
>
> System.Text.StringBuilder sb = new System.Text.StringBuilder();
>
> int charCode;
>
> for( int i = 0; i < text.Length; i++)
>
> {
>
> charCode = (Int32) text[i];
>
> sb.Append(String.Format("&#{0};",charCode));
>
> }
>
> return sb.ToString();
>
> }


None of this is necessary at all, *if* you use the correct requestEncoding/responseEncoding
for your pages...

Cheers,
--
Joerg Jooss
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string with control character in caret notation to realcontrol character string. Bart Vandewoestyne C Programming 8 09-25-2012 12:41 PM
FAQ 4.31 How can I split a [character] delimited string except when inside [character]? PerlFAQ Server Perl Misc 0 04-13-2011 10:00 PM
FAQ 4.31 How can I split a [character] delimited string except when inside [character]? PerlFAQ Server Perl Misc 0 01-25-2011 05:00 AM
How can I replace all occurrences of a character with another character in std string? herman C++ 5 08-30-2007 09:05 AM
8 bit character string to 16 bit character string Brand Bogard C Programming 8 05-28-2006 05:05 PM



Advertisments