如何从C#中的字符串中提取特定单词 [英] How to extract a particular word from a string in C#
问题描述
我有输入字符串
44/1,Cell:+ 91- 112222112 Mail:abcde@gmail.com
我的输出字符串需要是abcde@gmail.com
我如何才能实现这一目标在C#
我需要删除所有信件到邮件:
我尝试过:
i尝试Indexof()
对于Indexof我需要用一个字符替换Mail:然后我可以得到abcde@gmail.com使用子字符串函数
i have an Input string
"44/1,Cell: +91- 112222112 Mail:abcde@gmail.com"
my out put string needs to be "abcde@gmail.com"
How i can achieve this in C#
I need to remove all letters up to Mail:
What I have tried:
i tried Indexof()
For Indexof i need to replace "Mail:" with a character then i can get "abcde@gmail.com" using Sub string function
推荐答案
试试这个,前提是您的输入将以这种方式(最后的电子邮件)
try this, provided your input will be in this manner ( email at the last)
string input = "44/1,Cell: +91- 112222112 Mail:abcde@gmail.com";
string email = input.Substring(input.IndexOf("Mail:")).Replace("Mail:", "");
尝试:
Try:
string testString = "44/1,Cell: +91- 112222112 Mail:abcde@gmail.com";
string sub = testString.Substring(testString.IndexOf("Mail:") + 5);
Console.WriteLine(sub);
在检查之前此链接 [ ^ ]和< a href =http://www.dotnetperls.com/indexof>此链接 [ ^ ]了解两个非常常见的String函数是如何工作的。
希望它有所帮助。
Prior to that check this link[^] and this link[^] to understand how two very common String function works.
Hope it helps.
string[] strAry = "44/1,Cell: +91- 112222112 Mail:abcde@gmail.com".Split(':');
foreach (var item in strAry)
{
bool isEmail = Regex.IsMatch(item, @"\A(?:[a-z0-9!#
这篇关于如何从C#中的字符串中提取特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!