How to split a string into a list of strings in C#

3 Answers

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        string str = "java c# c c++ python";
        
        string[] arr = str.Split(' ');
        List<string> wordsOfStr = new List<string>(arr);

        foreach (string s in wordsOfStr) {
            Console.WriteLine(s);
        }
    }
}
 
 
 
/*
run:
   
java
c#
c
c++
python
   
*/

 



answered May 9, 2024 by avibootz
0 votes
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main() {
        string str = "java c# c c++ python";
        
        List<string> wordsOfStr = str.Split(' ').ToList();

        foreach (string s in wordsOfStr) {
            Console.WriteLine(s);
        }
    }
}
 
 
 
/*
run:
   
java
c#
c
c++
python
   
*/

 



answered May 9, 2024 by avibootz
0 votes
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main() {
        string str = "java c# c c++ python";
         
        List<string> wordsOfStr = new List<string>(str.Split(' '));
 
        foreach (string s in wordsOfStr) {
            Console.WriteLine(s);
        }
    }
}
  
  
  
/*
run:
    
java
c#
c
c++
python
    
*/

 



answered Apr 3 by avibootz
...