using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PracticeReview
{
class Program
{
static void Main(string[] args)
{
#region 编写函数,实现类似.net中Trim()函数功能:去掉字符串两端的空格,例如将字符串" hello world,你 好 世界 ! "两端空格去掉,并且将其中的所有其他空格都替换成一个空格,输出结果为:"hello world,你 好 世界 !"
string str = " hello world,你 好 世界 ! ";
////Trim()方法直接去掉字符串两边空格
//str = str.Trim();
//Console.WriteLine("====" + str + "===");
string testStr = TestTrim(str);
Console.WriteLine("====" + testStr + "===");
//使用Split按空格分割,重载方法,StringSplitOptions.RemoveEmptyEntries返回一个不包含空字符的数组,使用这个参数要求第一个参数为字符数组
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PracticeReview
{
class Program
{
static void Main(string[] args)
{
#region 编写函数,实现类似.net中Trim()函数功能:去掉字符串两端的空格,例如将字符串" hello world,你 好 世界 ! "两端空格去掉,并且将其中的所有其他空格都替换成一个空格,输出结果为:"hello world,你 好 世界 !"
string str = " hello world,你 好 世界 ! ";
////Trim()方法直接去掉字符串两边空格
//str = str.Trim();
//Console.WriteLine("====" + str + "===");
string testStr = TestTrim(str);
Console.WriteLine("====" + testStr + "===");
//使用Split按空格分割,重载方法,StringSplitOptions.RemoveEmptyEntries返回一个不包含空字符的数组,使用这个参数要求第一个参数为字符数组

本文展示了如何使用C#实现字符串两端空格的去除并替换连续空格,以及统计并获取特定字符在字符串中的出现次数和索引。此外,还介绍了如何生成10个1-100间不重复的随机偶数。
最低0.47元/天 解锁文章
4303

被折叠的 条评论
为什么被折叠?



