How to implement string[] into string[] in C#?

Related searches

I want to implement 'string[] loadedText' into 'string[] dataList', but I keep getting an error saying "Cannot implicitly convert type 'string[]' to 'string'".

string[] dataList = new string[1800];
StreamReader loadNewData = new StreamReader("podaciB.txt");
int i = 0;
while (i < 1800)
{
    string[] loadedData = loadNewData.ReadLine().Split(';');
    dataList[i] = loadedData;
    i++;
}

I need the 'dataList' array that will contain 1800 'loadedData' arrays which contain 4 strings in them.

It seems you need an array of array of strings, something like string[][].

You can do it like this:

string[][] dataList = new string[1800][];
StreamReader loadNewData = new StreamReader("podaciB.txt");
int i = 0;
while (i < 1800)
{
    string[] loadedData = loadNewData.ReadLine().Split(';');
    dataList[i] = loadedData;
    i++;
}

Strings in C, Below is an example to declare a string with name as str and initialize it with “ GeeksforGeeks”. 1. char str[] = "GeeksforGeeks"; 2. char str[50]� your loadedData is an array of string and dataList as well. But when you access dataList[i] you are in a string right now and compiler waiting a string to assign it. – darcane May 11 '19 at 14:35

What you need is a jagged array:

string[][] dataList = new string[1800][];

How to Append a Character to a String in C, Get the string str and character ch. Use the strncat() function to append the character ch at the end of str. strncat() is a predefined function used for string handling. string. h is the header file required for string functions. Print or return the appended string str. The String.Split() method splits a string into an array of strings separated by the split delimeters. The split delimiters can be a character or an array of characters or an array of strings. The code examples in this article discuss various forms of String.Split method and how to split strings using different delimiters in C# and .NET.

loadNewData.ReadLine().Split(';'); returns array of string and you are storing array of strings into dataList[i] i.e. string element of string array. This is the reason behind error which you mentioned in your question

If you want to store loadNewData.ReadLine().Split(';'); into an array then I would suggest you to use nested list List<List<string>>

Something like,

List<List<string>> dataList = List<List<string>>();
StreamReader loadNewData = new StreamReader("podaciB.txt");
int i = 0;
while (i < 1800)
{
    var innerList = loadNewData.ReadLine().Split(';').ToList();
    dataList.Add(innerList);
    i++;
}

C - Strings, C - Strings - Strings are actually one-dimensional array of characters terminated by a null character '\0'. Thus a The following declaration and initialization create a string consisting of the word "Hello". If you follow the rule of array initialization then you can write the above statement as follows − char greeting[] = "Hello";. How to parse strings using String.Split in C#. 01/03/2018; 2 minutes to read +3; In this article. The String.Split method creates an array of substrings by splitting the input string based on one or more delimiters. This method is often the easiest way to separate a string on word boundaries.

As you are splitting loadedNewData, you receive string[] already, because Split() function returns string[].

Array Of C String - How to play with strings in C, If a C string is a one dimensional character array then what's an array of C You can use any function on arr[x] that works on string! Following example concatenates all strings in a string array with space between them into a single string: 1. As you can see in the above example, a valid numeric string can be converted to an integer. The Parse() method allows conversion of the numeric string into different formats into an integer using the NumberStyles enum e.g string with parentheses, culture-specific numeric string, with a currency symbol, etc.

Search Within A String - How to play with strings in C, char str[] = "finding first and last occurrence of a character is amazing";. We'll loop through all lower case characters. Let's define a character array for that and write � In C#, you can use strings as array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.

public override string ToString(){} Implement the method so that it returns a string. The following example returns the name of the class in addition to the data specific to a particular instance of the class.

How to convert a string to a number (C# Programming Guide) 02/11/2019; 4 minutes to read +10; In this article. You can convert a string to a number by calling the Parse or TryParse method found on the various numeric types (int, long, double, etc.), or by using methods in the System.Convert class.

Comments
  • your loadedData is an array of string and dataList as well. But when you access dataList[i] you are in a string right now and compiler waiting a string to assign it.
  • Can you please elaborate your answer