Abhilash J A

Abhilash J A

  • 533
  • 2.4k
  • 598.1k

Split String in C#

Mar 30 2017 1:31 AM
Hi,
 
I want to split integer from string. For that, I have done like this,
  1. public void Main(string[] args)  
  2.         {  
  3.             string obj = "Rs. 1 to 100 employees.";              
  4.   
  5.             int A = 0;  
  6.             int B = 0;  
  7.   
  8.             string[] listTurnOver = obj.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();  
  9.             bool isfist = true;  
  10.             for (int i = 0; i < listTurnOver.Count(); i++)  
  11.             {  
  12.                 int temp = 0;  
  13.                 int.TryParse(listTurnOver[i], out temp);  
  14.                 if (temp != 0)  
  15.                 {  
  16.                     if (isfist)  
  17.                     {  
  18.                         A = temp;  
  19.                         isfist = false;  
  20.                     }  
  21.                     else  
  22.                     {  
  23.                         B = temp;  
  24.                     }  
  25.                 }  
  26.             }  
  27.         } 
 Let's say, If my string is containing 3 intergers, then how can I split and assigned to another int vartible?
  1. string obj2 = "1 to 100 employees with average of  10 percentage.";  
  2.   
  3. int C = 0;  
  4.   
  5. /*int c = ?*/ 
 
 
 
 

Answers (5)