关于字符串操作的一些常用户到的一些基本东西..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace string_传智博客园_
{
class Program
{
static void Main(string[] args)
{
#region 接受用户的输入字符串,反序输出"abc"->"cba"
//接受用户的输入字符串,反序输出"abc"->"cba"
//string s = Console.ReadLine();
//for (int i=s.Length-1;i >=0; i--)
//{
// Console.Write(s[i]);
//}
//s[2]=c,s[1]=b,s[0]=a; 我们通过下标2到0不就输出对应的值?即反序输出
#endregion
#region 接受用户输入一句英文,将其中的单词反序输出。"hello c sharp"->"sharp c hello"
//接受用户输入一句英文,将其中的单词反序输出。"hello c sharp"->"sharp c hello"
//string sp = Console.ReadLine();
//string[] words = sp.Split(' ');
//for (int i = words.Length - 1; i >= 0;i-- )
//{
// Console.Write(words[i]+" ");
//}
#endregion
#region abc@qq.com 取出abc 和qq.com
/* //abc@qq.com 取出abc 和qq.com
string email = Console.ReadLine();
int atIndex = email.IndexOf('@');
string usename = email.Substring(0, atIndex);
string 域名 = email.Substring(atIndex+1);
Console.WriteLine(usename);
Console.WriteLine(域名);
*/
#endregion
#region ini格式文件
string[] line = File.ReadAllLines(@"C:\Users\Administrator\Desktop\string(传智博客园)\string(传智博客园)\txt\sp.txt", Encoding.Default);
foreach (string item in line)
{
string[] strs = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string title = strs[0];//标题
string author = strs[1];//作者
if (title.Length > 17)
{
title = title.Substring(0, Math.Min(17, title.Length));
title = title + "....";
}
else
{
title = title;
}
Console.WriteLine("{0}+++++{1}", title, author);
}
#endregion
}
static string GetString(string fileURL, string fileName)
{
string[] sp = File.ReadAllLines(fileURL, Encoding.Default);
foreach (string item in sp)
{
string[] sts = item.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
string name = sts[0];
string value = sts[1];
if (name == fileName)//或者不要分割字符 直接 name.Trim()也可以;
{
return value.Trim();
}
}
return "错误";
}
}
}