473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

getting the character code of a character in a string

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
9 2249
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
(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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Surya Kiran | last post by:
Hi all, I'm facing a wierd problem. I've a file, which is getting updated every now and then. and i'm having another program, which monitors the file. I've to read the file line by line, and in...
5
by: Mike Murray | last post by:
Hi I have the following issue. I have a character that is return by a SQL Server database "É" to be precise, the issue is that when I store character in a .net string variable my understanding...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
5
by: Durgesh Sharma | last post by:
Are there no genric Macros in c to represent Integers,Characters,...or other data types ? I want to pass that MACRO (representing an alpha numeric Character)to that strrchar() function,to get the...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
22
by: Mike Polinske | last post by:
I am new to the C programming language but have been programming in Cobol for over 10 years. When I compile the following code, it compiles clean but I get an application error both under Windows...
1
by: foolygoofy26 | last post by:
what is the code to get the value of a special character in a C++ string. Like getting the 3 character of the string "Hello world" it would be "l". also what is the code to make a string all...
2
by: waltbrad | last post by:
Hello. Been studying Python for about a week now. I did a quick read of the tutorial in the manual and I'm reading Programming Python by Mark Lutz. I'm still getting used to the Python syntax,...
18
by: nar0122 | last post by:
//Nicholas Riseden //CSCI 3300 //Assignment 4 Version 2 #include "tree.h" #include "pqueue.h" #include <string> #include <fstream> #include <iostream> #include <stdio.h>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.