getting the character code of a character in a string

  • Thread starter Thread starter Velvet
  • Start date Start date
V

Velvet

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
 
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
 
This doesn't work... won't even compile.

sorry...


Winista said:
(Int32)email;

Velvet said:
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
 
byte[] emailBuff = Encoding.ASCII.GetBtyes(email);
for( i = 0; i < emailBuff.length; i++)
{
int char = (int) emailBuff;
uniemail += string.format("&#{0};",char);
}

-- bruce (sqlwork.com)
 
My mistake... case sensitivity got me. Looks like this is working!
THANKS!

Velvet


Velvet said:
This doesn't work... won't even compile.

sorry...


Winista said:
(Int32)email;

Velvet said:
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

 
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;

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

}


return sb.ToString();

}
 
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 said:
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;

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

}


return sb.ToString();

}




Velvet said:
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
 
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;

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top