By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

getting the character code of a character in a string

P: n/a
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
Jan 18 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Velvet,

System.Convert.ToChar("V")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Velvet" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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

Jan 18 '06 #2

P: n/a
(Int32)email[i];

"Velvet" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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

Jan 18 '06 #3

P: n/a
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:%2****************@TK2MSFTNGP10.phx.gbl...
Velvet,

System.Convert.ToChar("V")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Velvet" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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


Jan 18 '06 #4

P: n/a
This doesn't work... won't even compile.

sorry...
"Winista" <na*********@hotmail.com> wrote in message
news:uH*************@TK2MSFTNGP09.phx.gbl...
(Int32)email[i];

"Velvet" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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


Jan 18 '06 #5

P: n/a
My mistake... case sensitivity got me. Looks like this is working!
THANKS!

Velvet
"Velvet" <ve****@newsgroups.nospam> wrote in message
news:uj***************@TK2MSFTNGP14.phx.gbl...
This doesn't work... won't even compile.

sorry...
"Winista" <na*********@hotmail.com> wrote in message
news:uH*************@TK2MSFTNGP09.phx.gbl...
(Int32)email[i];

"Velvet" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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



Jan 18 '06 #6

P: n/a
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" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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

Jan 18 '06 #7

P: n/a
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" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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

Jan 18 '06 #8

P: n/a
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" <ve****@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <ve****@newsgroups.nospam> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
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


Jan 18 '06 #9

P: n/a
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
ne********@joergjooss.de
Jan 19 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.