Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to separate character and number part from string
    text
    copied!<p>E.g., I would like to separate: </p> <ul> <li><code>OS234</code> to <code>OS</code> and <code>234</code></li> <li><code>AA4230</code> to <code>AA</code> and <code>4230</code></li> </ul> <p>I have used following trivial solution, but I am quite sure that there should be a more efficient and robust solution .</p> <pre><code>private void demo() { string cell="ABCD4321"; int a = getIndexofNumber(cell); string Numberpart = cell.Substring(a, cell.Length - a); row = Convert.ToInt32(rowpart); string Stringpart = cell.Substring(0, a); } private int getIndexofNumber(string cell) { int a = -1, indexofNum = 10000; a = cell.IndexOf("0"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("1"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("2"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("3"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("4"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("5"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("6"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("7"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("8"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } a = cell.IndexOf("9"); if (a &gt; -1) { if (indexofNum &gt; a) { indexofNum = a; } } if (indexofNum != 10000) { return indexofNum; } else { return 0; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload