Manually Converting Between ASCII And Net Characters?

Feb 5, 2010

I am working on writing some code to scrub user input to my ASP.NET site. I need to scrub input to remove all references to ASCII characters 145, 146, 147, 148 which are occasionally getting input from my mac users who are copying and pasting content they write in a word processor on their macs.

My issue is the following three strings I am led to believe should output the same text.

string test1 = Convert.ToChar(147).ToString();
string test2 = String.Format("'{0}'", Convert.ToChar(147));
char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[] { 147 });
string test3 = new string(characters);

Yet when I set an ASP TextBox to equal the following

txtShowValues.Text = test1 + "*" + test2 + "*" + test3;

I get a blank value for test1, test2 works correctly, and test3 outputs as a '?'.

Can someone explain what is happening differently. I am hoping this will help me understand how .NET is using ASCII values for characters over 128 so that I can write a good scrubbing script.

EDIT
The values I mentioned (145 - 148) are curly quotes. So single left, single right, double left, double right.

By "works correctly" I mean it outputs a curly quote to my browser.

SECOND EDIT
The following code (mentioned in an answer) outputs the curly quotes as well. So maybe the problem was using ASCII in test 3.

char[] characters2 = System.Text.Encoding.Default.GetChars(new byte[] { 147 });
string test4 = new string(characters2);

THIRD EDIT
I found a mac that I could borrow and was able to duplicate the problem. When I copy and paste text that has quote symbols in them from Word into my web app on the mac it pastes curly quotes (147 and 148). When I hit save curly quotes are saved to the database, so I will use the code you all helped me with to scrub that content.

FOUTH EDIT
Spent some time writing more sample code based on the responses here and noticed it has something to do with MultiLine TextBoxes in ASP.NET. There was good info here, so I decided to just start a new question: http://stackoverflow.com/questions/2215547/asp-net-multiline-textbox-allowing-input-above-utf-8

View 3 Replies


Similar Messages:

C# - How To Get ASCII For Non-numeric Characters In A Given String

Nov 12, 2010

I will have my string as follows

String S="AB-1233-444";

From this i would like to separate AB and would like to find out the ASCII for that 2 alphabets.

View 5 Replies

SQL Server :: Selecting ASCII Characters From Ntext Column?

Dec 30, 2010

I have a Table with three columns :

MessageID (int)
MessageText (ntext)
ChannelID (int)

Now i want to get the list of message IDs where the message Text Contains some Special characters as like the characters from the below image. how to query to get the list of message ids where the message text contains any one of this special characters.

View 5 Replies

Manually Converting Result Dataset To JSON?

Mar 3, 2011

I have DataReader that holds the results from a stored procedure caal. The results consist of two fields ...

UserID
UserName

Normally I bind these results to an ASP.NET dropdownlist control ...

ddlUserList.DataSource = rdr // rdr is the DataReader
ddlUserList.DataTextField = "UserName"
ddlUserList.DataValueField = "UserID"
ddlUserList.DataBind()

However I am now trying to accomplish the same thing using jQuery AJAX. What I am stuck on is how to manually convert the dataset held in the DataReader to JSON. How are multiples values separated? Does this look correct?

{{"UserID":1, "UserName":"Bob"}, {"UserID":2, "UserName":"Sally"},{"UserID":3, "UserName":"Fred"}}

I realize there are libraries out there such as JSON.NET to handle the serialization but I am in the learning stage now and want to make sure I understand everything from the bottom up.

View 1 Replies

Manually Entering Special (unicode/international/extended) Characters In The URL Bar

Jan 6, 2010

I want to create a page that can read extended characters in the QueryString. While this normally is not a problem, there is one case where I don't manage: when the QueryString is manually entered (or even pasted).

Here is a simple test-case:

[Code]....

This works fine both when clicking the hyperlink or submitting the form. However, when you enter the special characters manually in the URL, or in some browsers even when you just highlight the URL bar and click Enter to open the page, the characters will be mangled. (You may need to empty your cache or perform a forced refresh to see these results.

In Internet Explorer 8:

Clicking the hyperlink shows the characters unencoded in the URL bar. Submitting the form shows the characters double-byte encoded (for example, the first character "Ã¥" (small letter a with ring above, unicode position 0xA5) is encoded as %C3%A5 instead of just as %A5. In both cases, the output shows the correct characters.After clicking the hyperlink (which creates an URL with readable characters), clicking the URL bar to highlight the URL and pressing Enter to open the page, shows square boxes instead of the characters as output. Note that you may have force a reload of the page to see this. The same happens when you enter characters manually in the URL bar.Highlighting the URL bar and submitting the double-byte encoded URL (as it is created by the form) shows the output as it should.Manually entering single-byte encoded characters ("%A5%B8%A6") will again show boxes instead of characters.

View 3 Replies

What Does The 0 Stand For In Encoding.ASCII.GetBytes (str) [0]?

Jan 20, 2010

,What does the [0] in this code stand for ?I know the line gets the number of bytes in the ASCII characters, if its less than 91 and greater than 64.But why the [0] string str = strs[i];
if (Encoding.ASCII.GetBytes(str)[0] <= 64 || Encoding.ASCII.GetBytes(str)[0] >= 91)
{
Console.WriteLine(Encoding.ASCII.GetBytes(str)[0].ToString());
}
else if (Encoding.ASCII.GetBytes(str)[0] != 88)
{
Console.WriteLine(str);
}

View 3 Replies

Convert Text In Textbox To Ascii?

Mar 10, 2010

In .net streams are by default encoded in utf-8. so what i want to do is to simply read the text in a textbox in which i paste the russian characters and then convert them to ascii. but when i debug the code then in my resulting string ? appears. how i can convert the string into its ascii equivalent. my code is given below

string inputString = txtName.Text;
ASCIIEncoding ascii = new ASCIIEncoding();
Encoding encoder = ASCIIEncoding.GetEncoding("us-ascii", new EncoderReplacementFallback(string.Empty), new DecoderExceptionFallback());
byte[] bAsciiString = encoder.GetBytes(inputString);
string cleanString = ascii.GetString(bAsciiString);

View 6 Replies

HttpUtility.HtmlDecode Cannot Decode ASCII Greater Than 127?

Oct 22, 2010

I have a list of character that display fine in WebBrowser in the form of encoded characters such as € &#65533; ... But when posting these characters onto server to I realized that HttpUtility.HtmlDecode cannot convert them to characters as browser did, they all become space.

text = System.Web.HttpUtility.HtmlDecode("€");

I expect it to return € but it return space instead. The same thing happen for some other characters as well.

View 2 Replies

Open Web Application If It Is Hosted In Non-ascii Computername?

Jul 10, 2010

My computername is in non-ascii character like ÄÖßÜÄÖßÜ. I am opening the web application using the url http://localhost/test/login.aspx. It opens with that url. But when i try to open with the url like http://ÄÖßÜÄÖßÜ/processmanager/login.aspx, it is not opening the page.

View 2 Replies

Convert Ascii HTML Code To Character?

Jan 5, 2011

i get some data from imdb using regexwhen getting title like Miller's Crossing and inserting it to my database there is a problemi get data and write on screen Response.Write(imdb.Title) it shows as Miller's Crossing that is the correct onebut after insert it to my database in Title field of table it is shown as Miller's Crossing so i dont want thishow can i convert those special characters when inserting to my datasbase ?

View 2 Replies

Strings Clarification - Biggest Character Using Ascii Values?

Mar 22, 2010

i have i doubt. any body clarify this doubts. Find biggest character in a string. using ascii values.

View 3 Replies

Website Not Producing ASCII Code For Small Alphabets?

Jan 12, 2011

i am developing a web site in which i need keyboard handling. My code for keyboard handling is working properly, but the problem is this, it produce same ASCII code for small and capital alphabets. For example when I execute my web site and press "A" without Caps-Lock it produce 65 ASCII code which is actually code of capital "A", But logically it has to produce "97" code of small "a"..

View 4 Replies

Outputing A Text File Of 1s And 0s - Convert Binary To Ascii?

Feb 13, 2010

I am outputing a text file of 1s and 0s. I want to shrink the file so I'm going to convert it to ascii. Its going to be used on a clientside web application so I can convert it back to binary with some scripting later on.

So, I want to convert the string of binary to a string of ascii serverside in vb.net. I have spent much time searching the web for a vb.net solution, and, what a mess!! everyone thinks they know how to do it, but none of the solutions have worked so far!!

View 5 Replies

How To Count Of Characters Entered In Multiline Textbox Till 140 Characters

Dec 13, 2010

How to count no. of characters entered in multiline textbox, i wanna enter maximum 140 characters in my multiline textbox using vb.net ...

In short i want textbox to enter limit is only 140 characters ....

i have te following code to do that .... but i wanna implement 140 characters limit in multiline textbox :

<script type="text/javascript">
function Count(x) {
document.getElementById("Label1").innerHTML = document.getElementById("TextBox2").value.length;
}
</script>
<asp:TextBox ID="TextBox2" runat="server" Height="78px"
TextMode="MultiLine" Width="224px" onkeyup="Count(this.id)"
MaxLength="140"></asp:TextBox>

View 3 Replies

AJAX :: MaskedEditExtender's - Mask Characters Don't Hide Under Typing Characters

Feb 1, 2010

I have a problem with MaskedEdit's mask for the code shown below:

[Code]....

When I'm starting to print date in the TextBox, mask moves with characters. Mask characters don't hide under typing characters.

View 7 Replies

Trying To Prevent Users From Submitting Ascii Codes In A Textbox Using A RegularExpressionValidator?

Jul 30, 2010

I am trying to prevent users from submitting ascii codes in a textbox using a RegularExpressionValidator.

This works fine and I am able to display an error.

However when the user clicks on another button on the page I get the "A potentially dangerous Request.Form value was detected from the client" error. Is there a way to prevent this?

View 5 Replies

MVC String Formatting C# - By 100 Characters Make 4 Rows Each 25 Characters?

Aug 23, 2010

I have a string with 100 characters and it is for me too long in one line. I want to make NewLine after each 25 characters. For example:

Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."

View 2 Replies

Localization :: International Characters / Application Is Changing The Characters

Jan 5, 2011

I have a application that takes a tab delimited text file parses and the inserts the data. Some of the data has international characters. My problem is it appears that my application is changing the characters. For Example the file might contain something lke this Andrlová and is converting it to this Andrlov�

I am passing this into a sproc. The datatypes for my paramater & DB Field is nVarChar(50). If I insert the data directly into my table or if I call my sproc from a query window and pass in some data it works fine, but when my app touches the data it appears to get messed with.

View 3 Replies

Ajax - Carriage Return (ASCII Chr 13) Is Missing From Textbox Postback Values?

Oct 26, 2010

I have an ASP.NET TextBox with TextMode = TextBoxMode.MultiLine that is used within an AJAX Update Panel. The .Text value has been pre-set to a value that has multiple lines.

When using Chrome(7.0.517.41) or Firefox(3.6.11) working with the controls posted back value on the server the carriage return is lost if the user hasn't edited the pre-set value.

E.g.

Initial .Text value set when the page loads:

[code]....

View 1 Replies

Web Forms :: Polish Characters Appearing While Posting Polish Characters To A Web App

Mar 18, 2011

When i post some polish chacters to webapp , i am not able to extract the polish chaters properly . I am using request.parsm[0] to recive the text

View 3 Replies

How To Add Code Behind Manually

Jul 25, 2010

I have a website on the IIS but it has only the aspx file. Now I need to add the code behind for some pages. How do I go about this?

I've been trying to add the attribute "codebehind" and "autoeventwireup" on the top of the aspx file but no luck (the page_load event is not being called). Also, if I double click on the button from the design view in Visual Studio, it creates the javascript handle (not the server code).

View 2 Replies

VS 2008 How To Manually Add To A GridView

Apr 9, 2010

In the past I have always added rows of data by binding the gridview to a sqldatasource control. Is there a way to manually (by code) add rows myself from the VB code? I need to call a stored procedure by code and wrote the results one at a time to the gridview.

View 3 Replies

How Add Sub Header In Soap Manually

Feb 16, 2011

I am using web services in my applcation. I know when calling webservices the soap is created.

My requirement is to create soap sub header below like using vb.net code. Is it possible?

<SubHeader>
<username>sasi</username>
<password>infot</password>
</SubHeader>

View 3 Replies

Put An ImageButton In A TemplateColumn Manually?

Nov 17, 2010

I have to create a DataGrid with dynamic columns and I want to put an ImageButton in a TemplateColumn. If the DataGrid is NOT DYNAMIC, I put this code on the .aspx page like this : (this first part of code is just to explain, it isn't what I want to do)

[code]...

View 1 Replies

Create New Role Manually Using EF?

Nov 29, 2010

Using the Entity Framework that I generated. I have a Roles table created during the default system AspNetSqlRoleProvider security set-up.In the Roles table, I have an ApplicationId uniqueidentifier column. Which has a guid populated in it, which doesn't change for my application. I need to add a Role manually through my app using the entity framework. However, when creating my Roles object and setting Roles.ApplicationId. It expects a type of Guid. I have the ApplicationId in my web.config app settings. As it shouldn't change. But it is returned at string. I cannot type cast the value either to use in Roles.ApplicationId. What can I do to use my current ApplicationId value when trying to create a new role manually using the EF?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved