在给定的字符串索引中替换char? [英] Replacing a char at a given index in string?

查看:62
本文介绍了在给定的字符串索引中替换char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String没有 ReplaceAt(),并且我在如何制作一个能满足我需要的体面函数方面遇到了麻烦。我想CPU成本很高,但是字符串的大小很小,所以没关系

String does not have ReplaceAt(), and I'm tumbling a bit on how to make a decent function that does what I need. I suppose the CPU cost is high, but the string sizes are small so it's all ok

推荐答案

使用 StringBuilder

StringBuilder sb = new StringBuilder(theString);
sb[index] = newChar;
theString = sb.ToString();

这篇关于在给定的字符串索引中替换char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆