none
How to compare a string coming with integer values RRS feed

  • Question

  • I have an xml , there is one element that is coming as string.

    this element contains numerical values.

    Now it can be any numerical values including 0, 0.0, 0.00, 0.00 etc.

    I have to compare this element and return true if it contains any of the above zero values , and fals if it contains other than zero values.

    please help me in getting the solution for this.

    Thanks,

    Sachin


    Thanks, Sachin

    Tuesday, September 25, 2012 9:53 AM

Answers

  • Hi Sachin,

    Welcome to the MSDN Forum.

    Before you try Thorsten's suggestion, you need to split the string by comma.

    Because you have said it is a combination of numbers, so I suggest you try Regular Expression: [1-9]+

    when found it, so your function can return true, else, return false.

    I hope this will be helpful.

    If I have misunderstood anything, please feel free to follow up.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 26, 2012 11:23 AM
    Moderator

All replies

  • Hi,

    try double.TryParse

    http://msdn.microsoft.com/en-us/library/system.double.tryparse%28v=vs.110%29.aspx

    and compare the results. Or use Tryparse in combiantion with ToString() with a format string to compare against the string values

    http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

    http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

    Regards,

      Thorsten



    Tuesday, September 25, 2012 9:59 AM
  • Hi Sachin,

    Welcome to the MSDN Forum.

    Before you try Thorsten's suggestion, you need to split the string by comma.

    Because you have said it is a combination of numbers, so I suggest you try Regular Expression: [1-9]+

    when found it, so your function can return true, else, return false.

    I hope this will be helpful.

    If I have misunderstood anything, please feel free to follow up.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 26, 2012 11:23 AM
    Moderator