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 had error "cannot convert string[] to string"
string[] digitsArray = {dd, pp, ff, cc};
As digitsArray array of arrays and all "dd, pp, ff, cc" are arrays have string values
I think you want
string[][] digitsArray = {dd, pp, ff, cc};
As if you haven't been given enough solutions already - a LINQ version:
var digitsArray = new[]{dd, pp, ff, cc}.SelectMany(foo=>foo).ToArray();
If you want one-dimensional array - you can use Enumerable.Concat and Enumerable.ToArray:
string[] digitsArray = dd.Concat(pp).Concat(ff).Concat(cc).ToArray();
Related
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)
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 5 years ago.
Improve this question
public class itemObject { public string items; }
values - item = "name1,name2" or items = "item3"
Need linq to split by ',' if exists else one string array.
This doesnt require linq, its the default behaviour of String.Split
var array = items.Split(',');
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")
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
efStudent.sponsor = Convert.ToString(student.Sponsor);
My problem is that I can't convert the efStudent.sponsor which is a string to student.Sponsor, because it is a string[].
I need some help to convert it from string to string[].
To convert a string to string[], you can initialize a single-element array:
efStudent.sponsor = new string[] { Convert.ToString(student.Sponsor) };
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 8 years ago.
Improve this question
I want to get the previous chars from a certain char in a string.
For example: myString = "26+", so I want to get 26 without +. How can I do this?
Use Substring and IndexOf.
string str = "26+";
string requiredString = str.Substring(0, str.IndexOf('+'));
strings are immutable in C# and you have to assign the results to string itself or some other string.
The function String.Substring will do what you need.
yourString.Substring(0, keepCharactersBeforeHere);