Checking for a special character and end program if found

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wb4whd
    New Member
    • May 2010
    • 2

    Checking for a special character and end program if found

    Ok I have some code here from C#. If want to modify it so that if "sid' contains the special character "&" it will stop running the process instead of continuing on and writing the xml file. Can anyone help me with this?

    Code:
    sid = loc_url.Substring(index, loc_url.Length - index);
    (so basically, if sid contains "&" anywhere in it, end the program here instead of continuing below.)             
    
                    XmlDocument doc = new XmlDocument();
                    XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    doc.AppendChild(docNode);
    
                    XmlNode chunkDataNode = doc.CreateElement("ChunkData");
                    doc.AppendChild(chunkDataNode);
    
                    XmlNode fieldNode = doc.CreateElement("fields");
                    chunkDataNode.AppendChild(fieldNode);
    
                    XmlNode field6Node = doc.CreateElement("field6");
                    field6Node.AppendChild(doc.CreateTextNode(sid));
                    fieldNode.AppendChild(field6Node);
    Last edited by tlhintoq; May 4 '10, 06:42 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. [imgnothumb]http://img689.imagesha ck.us/img689/2685/codebuttonbytes com.png[/imgnothumb] More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Code:
      string test = "bob & mary";
                  if (test.Contains("&")) return;
      That Intellisense of Visual Studio really does work.
      As soon as you type
      test.
      The context menu pops up and shows you all the options you have with the variable. Including "Contains" which should stand out as what you are looking for.

      Comment

      • wb4whd
        New Member
        • May 2010
        • 2

        #4
        I apologize for missing the code mark ups, I did get the code working right before I checked back here but thanks for the help!

        Comment

        Working...