---
title: "How to get string"  
description: "How to get string"  
author: "Manmohan Jha"  
published: 2014-01-24  
updated: 2014-01-25  
canonical: https://www.mindstick.com/forum/1867/how-to-get-string  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get string

[string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) str="xyz,abcd,pqrst,123456"\
\
Show resutl like this....\
xyx\
abcd\
pqrst\
123456\
How???\
Please help me...

## Replies

### Reply by Manmohan Jha

Thanks, Mr Pawan & Mr Abhishek

### Reply by Manmohan Jha

```
int x = 0, j = 0;string s="xyz,abcd,pqrst,123456";for (int i = 0; i < s.Length; i++){   if (s[i] == ',')   {     if (j > 0)    {     x = i - j;     }    else    {        x = i;     }     MessageBox.Show(s.Substring(j, x).ToString();     j = i + 1;     }  }
```

### Reply by Anonymous User

use this code

string str="xyz,abcd,pqrst,123456"\
string[] value=str.Split(',');

for (int i = 0; i < value.Length; i++)\
{\
Console.WriteLine(value[i]);\
}

### Reply by Abhishek Singh

you need to split your String like this

```
string str="xyz,abcd,pqrst,123456"string [] arr=str.Split(',');for (int i = 0; i < arr.Length; i++)            {                Console.WriteLine(arr[i]);            }
```


---

Original Source: https://www.mindstick.com/forum/1867/how-to-get-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
