如何从字符串数组中读取元素 [英] How to read element from string array
本文介绍了如何从字符串数组中读取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果元素包含一些文本,如%phn%
那么如何从字符串数组中读取元素然后如何操作。如果元素包含像phn这样的文本,则复制该元素。
Words是一个字符串数组。在这里我要复制那个元素。
我尝试过的事情:
How to read element from string array if it contain some text like %phn%
then how to do it. if element contain text like phn then copy that element.
Words is a string array. here i want to copy that element.
What I have tried:
int index2 = Array.IndexOf<string>(words, "PHONE NUMBER: 9822002170 ");
string results = words[350];
推荐答案
如果你的意思是你有一个字符串数组,并且想要找到包含子字符串的第一个字符串,那么这并不困难:
If you mean that you have an array of strings, and you want to find the first string containing a substring, then it's not difficult:
string[] words = new string[] { "hello there", "this is text", "to find a substring", "or at least", "the first example substring" };
string first = words.FirstOrDefault(s => s.Contains("sub"));
if (first != null) Console.WriteLine(first);
这篇关于如何从字符串数组中读取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文