Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# String Manipulation

Posted on 2009-05-12
7
Medium Priority
?
612 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

772 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