c# - How to fix parsing int from string? -


i trying percent @ end of string (i.e. "50013 / 247050 [20%]" want 20 @ end.) reason keeps returning -1. problem code?

public int percent(string s) {     string outp = "-1";      if(s != null)     outp = s;      try     {         outp = s.substring(s.indexof("["), s.indexof("%"));     }     catch (argumentoutofrangeexception e)     {     }      int outt = int.parse(outp);     return outt; } 

the second parameter isn't index count. should this:

// because, don't want [, you'll add 1 index, int index1 = s.indexof("[") + 1; int index2 = s.indexof("%"); string outp = s.substring(index1, index2 - index1); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -