Method 1: Using ToCharArray() Method:
The ToCharArray()
method is used to convert a string into a character array. It returns an array of characters representing the original string.
string inputString = "Hello, World!";
char[] charArray = inputString.ToCharArray();
Output:
Hello, World!
Using Split() Method:
The Split()
method is used to break a string into an array of substrings based on a specified delimiter. This is particularly useful for parsing data.
string csvData = "apple,mango,banana,kiwi";
string[] fruitArray = csvData.Split(',');
Output:
apple
mango
banana
kiwi
Using LINQ:
For more advanced scenarios, LINQ (Language Integrated Query) can be employed. This method allows for fine-grained control over the conversion process.
string sentence = "Welcome to techihook";
char[] uniqueChars = sentence.Distinct().ToArray();
Output:
Welcom thik
Comments (0)