如果子字符串中的任何一个与另一个子字符串匹配,则意味着该字符串没有唯一字符。
您可以尝试运行以下命令确定字符串是否包含所有唯一字符的代码。该示例显示了 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# 中的子字符串的详细内容。
