Manisha Mali

Manisha Mali

  • 1.7k
  • 19
  • 1.9k

separate string 172X120X40 in s1=172,s2=120.s3=40 how it is

Aug 31 2016 2:52 AM
i am using mvc 5 ,entityframework,c# 
 
i am having string 172X120X40 .i want to separate this in to 3 separate variable 
s1=172,s2=120,s3=40
how will i do that.

Answers (2)

0
Rajeesh Menoth

Rajeesh Menoth

  • 67
  • 27k
  • 2.7m
Aug 31 2016 4:51 AM
Hi,
 
Code :
  1. using System;  
  2. public class Program  
  3. {  
  4. public static void Main()  
  5. {  
  6. string S1 = string.Empty;  
  7. string S2 = string.Empty;  
  8. string S3 = string.Empty;  
  9. string inputStr = "172x120x40";  
  10. string[] array = inputStr.Split('x');  
  11. Console.WriteLine("S1 = " + array[0]);  
  12. Console.WriteLine("S2 = " + array[1]);  
  13. Console.WriteLine("S3 = " + array[2]);  
  14. }  
  15. }  
Reference :
 
https://dotnetfiddle.net/6guPg1
0
Midhun Tp

Midhun Tp

  • 140
  • 13.2k
  • 1.5m
Aug 31 2016 3:59 AM
Hi,
Please try this code -
string s1, s2, s3;
string k = "172x120x40";
string[] arr = k.Split('x');
s1 = arr[0];
s2 = arr[1];
s3 = arr[2];