-2

I have a string which is in following format or comma separated format

s1 ,s2,s3,s4,and so on. I want to convert it into

s1
s2
s3
s4
..
..
..

I know how I can do this by using a loop but I want to do this by regex in c# and in java without using the loop can I achive this ???

Dmitry
  • 13,797
  • 6
  • 32
  • 48
Zahid Nisar
  • 802
  • 4
  • 15
  • 26
  • 3
    Thousands of question abouts this. Did you do a little of research before asking? string.Split no regex needed for this. – Steve May 08 '14 at 12:16
  • This is a very basic question, google for simple regex explanation. – Max May 08 '14 at 12:16
  • Convert the string and print in the console? Or store it in some list? – Hirak May 08 '14 at 12:17

3 Answers3

1

Here is how you can do it in Java.

public class MainProg {

    public static void main(String[] args) {
        String s = "s1,s2,s3,s4";
        String z = s.replaceAll(",", "\n");
        System.out.println(z);

    }

}
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
0

find : \s*,\s*

replace with : \n

aelor
  • 10,892
  • 3
  • 32
  • 48
0
String.Join(Environment.NewLine, myString.Split(','));
decPL
  • 5,384
  • 1
  • 26
  • 36