c# 两个字符串,s="aeiou",s2="welcome to Quantum Asia"
2017-04-21 12:57
357 查看
c# 两个字符串,s="aeiou",s2="welcome to Quantum Asia"
方案一:
使用while循环:
方案二:
递归:
方案一:
使用while循环:
static void Main(string[] args) { string s = "aeiou"; string s2 = "welecome to Quantum Asia"; char[] array = s.ToCharArray(); for (int i = 0; i < array.Length; i++) { while (true) { var index = s2.IndexOf(array[i]); if (index == -1) break; s2 = s2.Remove(index, 1); } } Console.WriteLine(s2); Console.ReadKey(); }
方案二:
递归:
static void Main(string[] args) { string s = "aeiou"; string s2 = "welecome to Quantum Asia"; char[] array = s.ToCharArray(); for (int i = 0; i < array.Length; i++) { s2 = GetStr2(array[i], s2); } Console.WriteLine(s2); Console.ReadKey(); } private static string GetStr2(char v, string s2) { var index = s2.IndexOf(v); if (index != -1) { s2 = s2.Remove(index, 1); s2 = GetStr2(v, s2); } return s2; }
相关文章推荐
- C#中进行字符串类型声明时,一个小写 "string ", 一个大写 "String ", 这两个类有什么区别呢?
- [汇编语言]-第九章 在屏幕中间分别显示绿底红色,白底蓝色字符串"welcome to masm!"
- asp.net(c#) datelist DataGrid 中截取字符串加"..." 和 鼠标放上去字符全部显示
- Welcome to .NET BY C#
- C# Tostring 格式化输出字符串全解
- C# 枚举类型转换字符串 Enum to string,枚举转换为下拉菜单 Enum DropDownList
- toCharArray()方法 和 Java中比较两个字符串是否相等equals方法
- "HOW TO: Create a Smooth Progress Bar in Visual C# .NET"的学习笔记
- C# string 字符串 "暂留" 的意思(还看不明)
- C# 3.0 CookBook: 二、字符与字符串处理(2):两个字符相比较时控制大小写
- 找出两个字符串中最大子字符串,如"abractyeyt","dgdsaeactyey"的最大子串为"actyet
- c# ToString() 格式化字符串
- asp.net(c#) datelist DataGrid 中截取字符串加"..." 和 鼠标放上去字符全部
- CLR via C# 读书笔记(六)关于"字符串留用"
- C# 3.0 Cookbook:一、字符与字符串处理(4):在比较两个字符串时控制大小写敏感性
- C#计算字符串长度(中文两个字符)
- 找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为"cad"
- asp.net(c#) datelist DataGrid 中截取字符串加"..." 和 鼠标放上去字符全部显示
- (C#) A demo on how to auto fill out the "account" value in log in web page in "WebBrowser" control.
- (C#)计算字符串排列组合数 如"abcd"组合数为24 "aabb"组合数为6