今天闲来无事,突然想写一个字符串操作类。不过时间有限,只写了一点点,以后有时间,每天都写几个函数加上。今天刚写的一点如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
string str = "hello world! hello everyone";
string str2 = StringHandler.RemoveSpaces(str);
Console.WriteLine(str2);
}
}
public class StringHandler
{
public static string RemoveSpaces(string str)
{
string temp = "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] != ' ')
temp += str[i];
}
return temp;
}
public static string Reverse(string str)
{
string temp = "";
for (int i = str.Length - 1; i >= 0; i--)
{
temp += str[i];
}
return temp;
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
string str = "hello world! hello everyone";
string str2 = StringHandler.RemoveSpaces(str);
Console.WriteLine(str2);
}
}
public class StringHandler
{
public static string RemoveSpaces(string str)
{
string temp = "";
for (int i = 0; i < str.Length; i++)
{
if (str[i] != ' ')
temp += str[i];
}
return temp;
}
public static string Reverse(string str)
{
string temp = "";
for (int i = str.Length - 1; i >= 0; i--)
{
temp += str[i];
}
return temp;
}
}
}
这个类虽然简单,但都写完了,字符串的操作应该就比较熟练了:)