Link to home
Start Free TrialLog in
Avatar of M3hcSS
M3hcSS

asked on

Replace string function in C# working in web forms but not win forms.

He says:

What am I missing here?
I have the following string:
string _node =  Individual_Program__Serious_Incidents_Sorted_by_Incident_Report 
I use the following C#

 _node.Replace(-,_).

I am trying to replace the dash with an underscore.  After the code executes, it is still a dash!!!
Any suggestions?

I reply back:
Heres your answer&

    protected void Page_Load(object sender, EventArgs e)
    {
                    string myNode=
                                @"Individual_Program__Serious_Incidents_Sorted_by_Incident_Report";
                    Label1.Text=myNode;
                    myNode=myNode.Replace("_","-").ToString();
                    Label2.Text=myNode;
    }

He says:
Im not using ASP.  This is in my code generator.

Its maddening& this doesnt work:

string _treeNode = ri.treeNodeName.Replace(" ", "_");
string_treeNode2 = _treeNode.Replace("-","_");

After that _treeNode2 still has the darn -.

I cant believe this is a bug&weird.  Ive googled and no help.

Avatar of p_davis
p_davis

myNode.Replace('_','-'). try single quotes
ASKER CERTIFIED SOLUTION
Avatar of aphillips
aphillips
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M3hcSS

ASKER

Another email from him. I think...aphillips might be on the right track.

Interesting, this works:

string test = "hello-has_Dash";
test = test.Replace("-","_");


but this doesnt work:

string test = "Program__Serious_Incidents_Sorted_by_Incident";
test = test.Replace("-","_");

Is the dash different in those two?!
Avatar of M3hcSS

ASKER

Hmm, I think the square thingy might be the cause of the problem. I need to check...
Avatar of M3hcSS

ASKER

Yeah, it was not an ASCII standard format.