Solved

C# String Manipulation

Posted on 2009-05-12
7
607 Views
Last Modified: 2012-06-21
Hi,

I have a GridView that contains a comapny name. The problem is that although the GridView displays the text correct e.g. 'Smtih & Sons', when my code gets the text from the cell, i am returned 'Smith & Sons'.

How can I get it to return what I can see on the screen?

Thanks.
protected void GridViewBrowseResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName.Equals("ViewFile"))
  {
    int index = Convert.ToInt32(e.CommandArgument);
    string myRootDir = BrowseType;
    string myCompanyDir = GridViewBrowseResults.Rows[index].Cells[1].Text;
    string mySubDir = myListDirectoryMap[index].File_Folder;
    string myFileName = GridViewBrowseResults.Rows[index].Cells[3].Text;
    myToolBox.SetAccessPath(myRootDir, myCompanyDir, mySubDir, myFileName);
    }
}
 
 
Watch Results:
 
index	                      0                   	int
myRootDir	                      "quotation"    	string
myCompanyDir	"Smith & Sons"	string
mySubDir	                     "12008"         	string
myFileName	                     "FQ-0000012008-0"	string

Open in new window

0
Comment
Question by:tedporter
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
ID: 24366739
myCompanyDir = Server.HTMLDecode(myCompanyDir);
0
 
LVL 9

Expert Comment

by:tculler
ID: 24367203
Yeah, the above will work perfectly; however, be aware that the ampersand (&) is not the only 'trick' character. There are a few more, as follows:

<   >
>   <
"    &quot;
&   &amp;
'    &apos; // Not always, though!

That's all I can think of off the top of my head, for now.
0
 
LVL 9

Expert Comment

by:tculler
ID: 24367217
Oh great, this site's system is even too ghetto to handle itself, lol. The first two lines are supposed to say

<  & gt;
>  & lt;

No spaces between the letters and the & though
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24367591
my post above should handle all of the characters...
0
 
LVL 9

Expert Comment

by:tetorvik
ID: 24371701
Setting BoundField.HtmlEncode to false will do the trick as well.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx

0
 

Author Comment

by:tedporter
ID: 24372247
Hi,

Thank you all for the posts. Tetorvik, I tried your suggestion but unfortunately, I had no success with it.
0
 

Author Closing Comment

by:tedporter
ID: 31580622
Thank you for the code. Works like a dream.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question