你可以使用正则表达式
string data = "lg-270-110.sh-300-110.hd-180-1.hr-155-61.ea-1403-62.cc-3007-110-110.ch-220-63.ca-3084-64-64";
//Match things that are preceded by a dot (.) (or the beginning of input)
// that begin with 'h' followed by a single letter, then dash, three digits,
// a dash, at least one digit, followed by a period (or the end of input)
var rx = new Regex(@"(?<=(^|\.))h\w-\d{3}-\d+(\.|$)");
//Get the matching strings found
var matches = rx.Matches(data);
//Print out the matches, trimming off the dot at the end
foreach (Match match in matches)
{
Console.WriteLine(match.Value.TrimEnd('.'));
}
//Get a new copy of the string with the matched sections removed
var result = rx.Replace(data, "").TrimEnd('.');
您是否尝试过RegEx? –
可能重复的[PHP - 从字符串中删除特定字符串](http://stackoverflow.com/questions/11382611/php-strip-a-specific-string-out-of-a-string) –
一种方法这是非常灵活的,但可能不够高性能的是使用我的[sscanf()替换为.NET](http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net)。它允许你定义占位符并提取你需要的任何部分。 –