code里面ReadLine()赋给了string,结果如果下一行比上一行要短的话,那么输出就是下一行+(上一行-下一行)的字符串
写了一个clearString,也不好用,快被烦死了,谁来救救我
code如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static public string cleanString(String s)
{
if (s != null && s.Length > 0)
{
for(int i=1;i<s.Length;i++)
{
s.Remove(s.Length - i);
s = s.Substring(0, s.Length - i);
}
}
return s;
}
static void Main(string[] args)
{
StreamReader city = File.OpenText("city.txt");
StreamReader state=File.OpenText("state.txt");
StreamReader street_suffix = File.OpenText("street-suffix.txt");
String str_city;
List<String> st_city= new List<string>();
WebClient client=new WebClient();
byte[] page = client.DownloadData("http://www.picturehistory.com/product/id/1937");
string content=System.Text.Encoding.UTF8.GetString(page);
Console.Write(content);
Console.ReadKey();
Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_city = city.ReadLine()) != null)
{ str_city.TrimEnd();
Regex myRegex = new Regex(str_city, RegexOptions.IgnoreCase);
if(myRegex.IsMatch(content))
{
st_city.Add(str_city);
Console.Write(str_city);
Console.ReadKey();
}
str_city = cleanString(str_city); } foreach (string cityItem in st_city)
{
Console.Write(cityItem);
Console.ReadKey(); }
String str_state;
List<String> st_state = new List<string>(); Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_state = state.ReadLine()) != null)
{
str_state.TrimEnd();
String regexState = "\b" + str_state + "\b";
Regex myRegex = new Regex(regexState, RegexOptions.IgnoreCase);
if (myRegex.IsMatch(content))
{
st_state.Add(str_state);
Console.Write(str_state);
Console.ReadKey();
}
} String str_street;
List<String> st_street = new List<string>(); Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_street = street_suffix.ReadLine()) != null)
{
str_street.TrimEnd();
String regexStreet="\b\\w+(?="+str_street+"\b)";
Regex myRegex = new Regex(regexStreet, RegexOptions.IgnoreCase);
if (myRegex.IsMatch(content))
{
st_street.Add(str_street);
Console.Write(str_street);
Console.ReadKey();
}
} }
}
}
写了一个clearString,也不好用,快被烦死了,谁来救救我
code如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static public string cleanString(String s)
{
if (s != null && s.Length > 0)
{
for(int i=1;i<s.Length;i++)
{
s.Remove(s.Length - i);
s = s.Substring(0, s.Length - i);
}
}
return s;
}
static void Main(string[] args)
{
StreamReader city = File.OpenText("city.txt");
StreamReader state=File.OpenText("state.txt");
StreamReader street_suffix = File.OpenText("street-suffix.txt");
String str_city;
List<String> st_city= new List<string>();
WebClient client=new WebClient();
byte[] page = client.DownloadData("http://www.picturehistory.com/product/id/1937");
string content=System.Text.Encoding.UTF8.GetString(page);
Console.Write(content);
Console.ReadKey();
Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_city = city.ReadLine()) != null)
{ str_city.TrimEnd();
Regex myRegex = new Regex(str_city, RegexOptions.IgnoreCase);
if(myRegex.IsMatch(content))
{
st_city.Add(str_city);
Console.Write(str_city);
Console.ReadKey();
}
str_city = cleanString(str_city); } foreach (string cityItem in st_city)
{
Console.Write(cityItem);
Console.ReadKey(); }
String str_state;
List<String> st_state = new List<string>(); Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_state = state.ReadLine()) != null)
{
str_state.TrimEnd();
String regexState = "\b" + str_state + "\b";
Regex myRegex = new Regex(regexState, RegexOptions.IgnoreCase);
if (myRegex.IsMatch(content))
{
st_state.Add(str_state);
Console.Write(str_state);
Console.ReadKey();
}
} String str_street;
List<String> st_street = new List<string>(); Console.WriteLine("Reading data and insterting into a StringTable.");
while ((str_street = street_suffix.ReadLine()) != null)
{
str_street.TrimEnd();
String regexStreet="\b\\w+(?="+str_street+"\b)";
Regex myRegex = new Regex(regexStreet, RegexOptions.IgnoreCase);
if (myRegex.IsMatch(content))
{
st_street.Add(str_street);
Console.Write(str_street);
Console.ReadKey();
}
} }
}
}
解决方案 »
- TextBox_Leave事件 执行两次
- 200分请教表达式树问题
- 当textbox为空白的时候就出错,该如何解决呢
- 首先非常感谢李逍遥昨天解决我了的问题, 我今天还想问一个在PDA里面怎么样获取GPS的信息,很急!!!!!!!!!!!!
- 当前线程不在单线程单元中..线程错误..?
- 日期格式改变方法?
- === 自定义控件的事件处理问题 (请saucer(思归)、Eddie005(暴走005)以及各位老大帮助)===
- 如何用C#重启本地计算机?
- 请教:如何修改ICON?
- 数据库和代码相同,在win2008 32bit正常, 在win2008 64bit排序出错,求指点
- 如何将Excel向导入到datagridview中去掉隐藏列
- 求FileUpload选择项的事件写法
string tcity="";static public string cleanString(string s)
{
string rest="";
if(s.Lenght>0)
{
if(tcity=="")
{
tcity=s;
rest=s;
}else{
if(s.Length<tciyt.Length)
{
rest=s+tcity.SubString(s.Lenght);
tcity=s;
}else{
rest=s;
tcity=s;
}
}
}
return rest;
}