1

I am trying to replace a sub-string in the errorString. i am using this code,which is not making any changes to errorString. am i following a wrong method?

 string errorstring = "<p>&nbsp;&nbsp;&nbsp;Name:{StudentName}</p>";
 errorstring.Replace("{StudentName}", "MyName");

i want to replace {StudentName} in errorString with "MyName"

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58

2 Answers2

1

Declare a new instance of that string:

string errorstring = "<p>&nbsp;&nbsp;&nbsp;Name:{StudentName}</p>";
errorstring = errorstring.Replace("{StudentName}", "MyName");

That should work if you don't use StringBuilder.

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
0

Please follow the below steps.

Step :- 1

 string errorstring = "<p>&nbsp;&nbsp;&nbsp;Name:{StudentName}</p>";
    errorstring = errorstring.Replace("{StudentName}", "MyName");

Step :- 2

@Html.Raw(errorstring)
Shahzad Khan
  • 432
  • 2
  • 14