Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# String Manipulation

Posted on 2009-05-12
7
Medium Priority
?
611 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 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
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!
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

721 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