Solved

C# String Manipulation

Posted on 2009-05-12
7
610 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
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…

615 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