如何使用C#.net在这些字符之间删除 [英] How to remove between those character using C#.net
本文介绍了如何使用C#.net在这些字符之间删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我想删除两个字符之间的
例如:
Hello,
I want to remove between Chars which
ex:
string s=website(14)\\.net(4);
我只想要
像s=website\\.net
一样,您可以引导或发送任何代码段吗?"
i want only
like s=website\\.net
can u guide or send any snippets''
推荐答案
Mohammad A Rahman 使用LINQ
给出的解决方案1是好的.另一种选择是使用Regex
,如下所示.
The Solution 1 given by Mohammad A Rahman usingLINQ
is good. Another alternative, is to useRegex
as shown below.
string text = "s=website(14)\\.net(4)";
string requiredText = Regex.Replace(text,@"\(\d*\)","");
Console.WriteLine (requiredText);
//Output
//s=website\.net
这可能对您有帮助,
It might help you,
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = @"website(14)\\.net(4)";
var result = new String(s.Where(x => !Char.IsNumber(x) && x!='(' && x!=')' ).Select(x => x).ToArray());
Console.WriteLine(result);
}
}
}
这将产生以下输出,
This will produce following output,
website\\.net
Press any key to continue . . .
有关位置和选择"的更多信息,请参见 ^ ]
希望对您有所帮助:)
For more information about the Where and Select please see How does it work in C#? - Part 3 (C# Linq in detail)[^]
Hope it helps :)
您可以使用正则表达式:
You can use Regex:
string s = @"website(14)\\.net(4)";
string result = Regex.Replace(@"\(\d*\)", string.Empty);
Console.WriteLine(result);
这篇关于如何使用C#.net在这些字符之间删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文