Csharp/C#教程:查看字符串中的每个字符分享


查看字符串中的每个字符

我想知道是否有人知道如何查看每个字符的字符串,然后将每个字符添加到新字符串? 只是一个非常基本的例子,我可以添加ToUpperToLowervalidation等。

 string foo = "hello world", bar = string.Empty; foreach(char c in foo){ bar += c; } 

使用StringBuilder

 string foo = "hello world"; StringBuilder bar = new StringBuilder(); foreach (char c in foo) { bar.Append(c); } 

下面是String class的签名:

 [SerializableAttribute] [ComVisibleAttribute(true)] public sealed class String : IComparable, ICloneable, IConvertible, IComparable, IEnumerable, IEnumerable, IEquatable 

https://msdn.microsoft.com/en-us/library/system.string(v=vs.100).aspx

 var output = ""; // or use StringBuilder foreach(char c in text) { output += c; // if or do with c what you need } 

……那是你需要的吗?
string是IEnumerable

上述就是C#学习教程:查看字符串中的每个字符分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1002571.html

(0)
上一篇 2021年12月28日
下一篇 2021年12月28日

精彩推荐