none
How to I check if string length equals zero in C#? RRS feed

  • Question

  • I have if statement if C# and I want to add a condition to check if string length equals zero for xml code 

    <xsl:when test="(Cancelled='True') and (string-length(RescheduledReason)=0)">Cancelled</xsl:when>

    Here is what I already have but I have not checked string length for RescheduledReason =0. This is what I need help to add it to my if statement.

    //HearingCancelled 

    if ((objxmlNode.SelectSingleNode("Cancelled") != null) && (objxmlNode.SelectSingleNode("Cancelled").InnerText == "True"))                       

    {   

    objPrepHearDoc.Hearing.Settings[i].SettingStatus = "Cancelled";                     

    }



    • Edited by winkimjr2 Tuesday, March 12, 2019 1:05 PM formatted the if statement
    Tuesday, March 12, 2019 1:04 PM

All replies

  • Hi winkimjr2,

    • Again, without seeing your input XML it is impossible to come up with any suggestion.
    • I think that I already suggested to you to start using LINQ to XML in c#.
      It is available in the .Net Framework for more than a decade.
    Tuesday, March 12, 2019 2:18 PM
  • Check this:

    If( … && string.IsNullOrEmpty(objxmlNode.SelectSingleNode("RescheduledReason")?.InnerText))

    Tuesday, March 12, 2019 5:46 PM
  • Try this out:

    HideCopy Code

    if ((objxmlNode.SelectSingleNode("RescheduledReason") != null) && (objxmlNode.SelectSingleNode("RescheduledReason").InnerText.Length == 0)

       
    Tuesday, March 12, 2019 6:09 PM