2

I have the following numbers as shown below:

1234567890

I would like to get the result as:

1
2
3
4
5
6
7
8
9
0

(Horizontal to Vertical). Please help me to achieve it via simple regex or through editplus.

Thanks in advance !!!

Donut
  • 110,061
  • 20
  • 134
  • 146
Bose
  • 21
  • 1

3 Answers3

5

You don't need a regular expression for this; all you're trying to accomplish is to insert a newline character between each element in your string.

If you're using C#, you can use the following:

string s = "1234567890";
string.Join(Environment.NewLine, s.ToCharArray());

Note that if your number is of a numeric data type (e.g., int), you'll likely need to convert it to a string. In C#, this is as simple as calling the .ToString() method, for example:

int x = 1234567890;
string s = x.ToString();
Donut
  • 110,061
  • 20
  • 134
  • 146
  • 1
    Your use of Environment.NewLine is exceptional :-) :-) I hadn't ever used it... I normally simply added a \n . (to be clear... I think it's more informative the Environment.NewLine than the rest of the response) – xanatos Mar 14 '11 at 20:59
3

sorry I don't have editplus, but this should work (tested in notepad++)

Find:

([0-9])

replace:

\1\r\n

make sure to have regular expression search on (this may only pertain to notepad++)

the () creates a regular expression group, that may then be back referenced via the "\1" (see the link for a primer) the "\r\n" are just CRLF

Harrison
  • 8,970
  • 1
  • 32
  • 28
  • Thanks for your help. i have even tried it for alphabets and it works ([a-z]). But i replaced as "\1\n". If i replace with "\1\r\n", the result is occuring with "\r" on edit plus. Also, if i have a set of information which is both alphabets & digits what is the best way to get the result in veritical order. EG: if a horizontal line looks "123456Yuiabcd9034", i would like to get a result in vertical order. – Bose Mar 14 '11 at 21:46
  • 1
    Then use `([0-9a-zA-Z])` this will find all numbers and letters – stema Mar 14 '11 at 21:54
  • agreed with @stema, that will capture numeric, and lower and upper alpha – Harrison Mar 14 '11 at 22:26
0

Replace . with &\n in editplus.

Nitesh
  • 180
  • 1
  • 11