Saturday 15 May 2010

Ways to extract double in a specific string format in C#? -



Ways to extract double in a specific string format in C#? -

we have string inputs of format hello_ep_-12.5_201414, welcome_ep_22.5_20345 etc

we have extract double value -12.5, 22.5 above strings. format *_ep_double_* fixed.

one way extract split strings '_' , take string next 'ep' , convert it. other way utilize regex, extract decimal value part. there other efficient way it?

try :

string input = "hello_ep_-12.5_201414"; int start = input.indexof("_ep_") + "_ep_".length; int length = input.indexof('_', start + 1) - start; double d; double.tryparse(input.substring(start, length), out d);

c# string

No comments:

Post a Comment