c# - 如何替换字符串中的子字符串,并获取包含替换子字符串的完整字符串?
问题描述
如何替换字符串中的子字符串,并获取包含替换子字符串的完整字符串?
string ex1 = "Example1";
string output;
for (int i = 0; i <= ex1.Lenght; i++)
{
if (ex1.Substring(i, 1).Contains("1")
{
output = ex1.Substring(i, 1).Replace("1", "!");
} // output is here ! but i want the complete string with the Replaced substring, like "Example!"
}
Console.WriteLine(output);
解决方案
String.Replace
自己做你想要的 - 不需要子字符串:
string output = ex1.Replace("1", "!");
推荐阅读
- oop - 当一个参与者有两个不同的场景时,如何呈现用例图?(完全相同的参与者)
- sql-server - 从 VS2019 IDE 调试 SQL Server 存储过程
- r - “二进制运算符的非数字参数”执行 R 脚本,Microsoft Azure
- discord.js - Discord.js TypeError:无法读取未定义的属性“get”
- single-sign-on - 无法为方法 [KEYCLOAK] 配置身份验证器
- javascript - Express 中间件仅用于处理 React 和 Python 之间的请求
- python - 需要正则表达式模式来解析字符串中相似的元素
- python-3.x - Selenium:无法关闭窗口警报
- excel - 连接如果,在一个范围内
- twitter-bootstrap - 折叠时引导导航栏菜单不下拉