您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 中的子字符串

2024/2/19 5:47:43发布18次查看
substring 用于在 c# 中获取字符串的子部分。为此,我们有 substring() 方法。使用 c# 中的 substring() 方法检查每个子字符串是否有唯一字符。循环它直到字符串的长度。
如果子字符串中的任何一个与另一个子字符串匹配,则意味着该字符串没有唯一字符。
您可以尝试运行以下命令确定字符串是否包含所有唯一字符的代码。该示例显示了 substring() 方法的用法 -
示例using system;using system.collections.generic;using system.linq;using system.text;using system.threading.tasks;public class demo { public bool checkunique(string str) { string one = ""; string two = ""; for (int i = 0; i < str.length; i++) { one = str.substring(i, 1); for (int j = 0; j < str.length; j++) { two = str.substring(j, 1); if ((one == two) && (i != j)) return false; } } return true; } static void main(string[] args) { demo d = new demo(); bool b = d.checkunique("amit"); console.writeline(b); console.readkey(); }}
以上就是c# 中的子字符串的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product