C# Multidimensional string Lists [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For my knowledge I want to understand about multidimensional string Lists in C#. Please can some one explain me with good example code of creating multidimensional string Lists and also retrieving data from it.
I want examples for the following
List<string[]>
List<string[,]>
List<List<string>>

Declare them just like any other list type:
List<string[]> list1 = new List<string[]>();
List<string[,]> list2 = new List<string[,]>();
List<List<string>> list3 = new List<List<string>>();
and access them like so:
// First and third use identical indexers:
string s1 = list1[0][0];
string s3 = list3[0][0];
// Second is similar, just with a multidimensional indexer instead
string s2 = list2[0][0,0];

Related

Get text patters from string using regular expression [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
In C# .NET
I have a string with
PSL44T-VK5VF-2B
PSL-44TVK5-VF2B
PS-L44-TVK-5VF-2B
using regular expression can I get the result format as
XXXXXX-XXXX-XX <- PSL44T-VK5VF-2B
PSL-XXXXXX-XXXX <- PSL-44TVK5-VF2B
XX-XXX-XXX-XXX-2B <- PS-L44-TVK-5VF-2B
XX-L44-XXX-XXX-XX <- PS-L44-TVK-5VF-2B
Your question is not clear. But if you want to filter a list of strings with regular expressions, you can do as follows:
List<string> inputs = new List<string>();
inputs.Add("PSL44T-VK5VF-2B");
inputs.Add("PSL-44TVK5-VF2B");
inputs.Add("PS-L44-TVK-5VF-2B");
var myRegex = new Regex("^PSL-.{6}-.{4}$"); // for PSL-XXXXXX-XXXX
List<string> resultList = inputs.Where(f => myRegex.IsMatch(f)).ToList();
and result:

How to convert list to string[] [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a List as following
List<string> email = File.ReadAllLines(fileName).ToList<string>();
filename is text I openFileDialog. The text in file txt is 3 line with 3 gmail
I want convert List to
string[] arRcpt = new string[] { };
The File.ReadAllLines(fileName) returns a string[]. You don't need to convert it into a list and then to string[]. You can directly assign it to an array.
string[] arRcpt = File.ReadAllLines(fileName)

Usinq Linq to get rows based on comma-separated value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have comma-separated data in my column called col1, and I have an array of strings
IEnumerable<string> year = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000"}
I have tried the following
searchfrom = searchfrom.Where(x => years.Contains(x.col1.Replace(',', ' '))).ToList();
and
searchfrom = searchfrom.Where(x => years.Contains(x.col1)).ToList();
I want that row which is match any "year" into "col1"
To optimize such queries, you should first convert your years collection into a hash set.
var years = new HashSet<string>(new [] { "1990", "1991", ... });
In your Where clause, you need to split the contents of each of your records, x, for which you can use x.Split(','). Then, you need to check whether any of these subparts are contained within the years collection.
var result = searchfrom.Where(x =>
x.Split(',').Any(years.Contains)
).ToList();

Find what number a string is in a List [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to be able to know what number a string is in one list so I can match it with a string in another list.
Something like:
myList[1] would be 1
myList2[5] would be 5
Sorry if I'm not clear, but this is really hard to explain.
The number you're referring to is called the index.
You can find the index of a string in your list by using the List<T>.IndexOf() method.
int indexOfFoo = myList.IndexOf("foo");
To find the index of a string in a list of strings:
var myList = new List<string> { "x", "y", "z" };
var indexOfY = myList.IndexOf("y");
You can use myList.IndexOf("string") to get the index of the item in your list.
http://msdn.microsoft.com/en-us/library/e4w08k17(v=vs.110).aspx
I'm not sure if that is what you're asking, but that is how I understood it.
try it:
yourList.IndexOf("urstring")

Reorder a List of string using LINQ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a list of string List which contains all state names.
I need to move few states(Ex New York, California etc) to appear at the top of the list.
How can I do this using LINQ?
FYI: the list is alreday sorted in alphabetical order.
Its just a simple List and few important states needs to be at the top. No criteria.
The following is a proof of concept using letters instead of states.
var all = new List<string>() {"a","b","c","d","e"};
var top = new List<string>() {"c","d"};
var finalList = top.Concat(all.Except(top));
The idea is that you have your full list of states (all) and a list of the ones you want at the top ('top'). You then take the ones at the top and concatenate the list of the remaining ones that you create using the Except method.
List<string> importantStates = {...};//It's up to you
var list = states.OrderBy(x=>!importantStates.Contains(x));

Categories