Solved

C# String Manipulation

Posted on 2009-05-12
7
601 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
Comment Utility
myCompanyDir = Server.HTMLDecode(myCompanyDir);
0
 
LVL 9

Expert Comment

by:tculler
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

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

Expert Comment

by:tetorvik
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for the code. Works like a dream.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now