C# Input string was not in a correct format int32 -
i having problems formats , converting.
i have tried workarounds , nothing.
code snippet think error is
label_map.text = message.substring(21, 3); label_sys.text = message.substring(15, 3); label_dia.text = message.substring(18, 3); label_pulse.text = message.substring(26, 3);  savedata(     int32.parse(message.substring(15, 3)),     int32.parse(message.substring(18, 3)),     int32.parse(message.substring(26, 3))); example input string
s1;a0;c03;m00;p120080100;r075;t0005;;d2 end of errorcode
innerexception: system.formatexception     message=input string not in correct format.    source=mscorlib    stacktrace:   @ system.number.stringtonumber(string str, numberstyles options, numberbuffer& number,  numberformatinfo info, boolean parsedecimal)   @ system.number.parseint32(string s, numberstyles style, numberformatinfo info)   @ nibp2pc.form1.display(string message) in c:\users\bazinga\desktop\spiediena_merisana\nibp2pc_c#\nibp2pc\form1.cs:line 427 
you might have more success trying parse out string want.
public class inputcapture {     public string attribute { get; set; }     public int value { get; set; } }  public class inputparser {     const string pattern = @"(\w)(\d+)";     private static readonly regex regex = new regex(pattern);      public ienumerable<inputcapture> parse(string input)     {         var inputs = input.split(new[] { ';' }, stringsplitoptions.removeemptyentries);         var parsedinputs = inputs.where(i => regex.ismatch(i))                              .select(i => regex.match(i))                              .select(r =>                                 new inputcapture                                     {                                         attribute = r.groups[1].value,                                         value = int.parse(r.groups[2].value)                                     });          return parsedinputs;     } } 
Comments
Post a Comment