ho trovato questo per te
codice:
//purpose: Replace the xth character in a string with a new character
//example: ReplaceXthCharacter("There are no tapos in this sentence.",14,'y');
//returns: A string is returned with the appropriate character replaced
//returns: If charater position is out of range, then the original string is returned unchanged
public string ReplaceXthCharacter(string mainString, int characterPosition, char newCharacter) {
//initialize
string rs = "";
string stringBeforeCharacter = "";
string stringAfterCharacter = "";
//get strings before and after character
try {
stringBeforeCharacter = mainString.Substring(0,characterPosition);
stringAfterCharacter = mainString.Substring(characterPosition + 1,mainString.Length - characterPosition - 1);
//build new string
rs = stringBeforeCharacter + newCharacter + stringAfterCharacter;
}
catch {
rs = mainString;
}
return rs;
}
*********************** An easier way to do this is:
<%@ Page Language="c#" %>
<script runat="server">
public void Page_Load(Object sender, EventArgs e) {
StringBuilder sb = new StringBuilder("There are no tapos in this sentence");
sb[14] = 'y';
Output.Text = sb.ToString();
}
</script>
<html>
<head>
</head>
<body>
<asp:Literal id="Output" runat="server"></asp:Literal>
</body>
</html>
preò ti assicuro che c'è anche ilk comando Replace prova ad includere System.