473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Checking for a special character and end program if found

2
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?

Expand|Select|Wrap|Line Numbers
  1. sid = loc_url.Substring(index, loc_url.Length - index);
  2. (so basically, if sid contains "&" anywhere in it, end the program here instead of continuing below.)             
  3.  
  4.                 XmlDocument doc = new XmlDocument();
  5.                 XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  6.                 doc.AppendChild(docNode);
  7.  
  8.                 XmlNode chunkDataNode = doc.CreateElement("ChunkData");
  9.                 doc.AppendChild(chunkDataNode);
  10.  
  11.                 XmlNode fieldNode = doc.CreateElement("fields");
  12.                 chunkDataNode.AppendChild(fieldNode);
  13.  
  14.                 XmlNode field6Node = doc.CreateElement("field6");
  15.                 field6Node.AppendChild(doc.CreateTextNode(sid));
  16.                 fieldNode.AppendChild(field6Node);
May 4 '10 #1

✓ answered by tlhintoq

Expand|Select|Wrap|Line Numbers
  1. string test = "bob & mary";
  2.             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.

3 1451
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

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.

More on tags. They're cool. Check'em out.
May 4 '10 #2
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. string test = "bob & mary";
  2.             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.
May 4 '10 #3
wb4whd
2
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!
May 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Pikkel | last post by:
i'm looking for a way to replace special characters with characters without accents, cedilles, etc.
1
by: quickcur | last post by:
I am rewrite some of my excel sheets to xml document. In my excel, there is a lot of special characters like "/", " " (space), "#", "+'. I am using a java program based on JDom to to create xml....
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
3
by: ATH0 | last post by:
How to search for special character { } and how to count them.. I got field called text ( undefined length ) and in this field you must define "{" as start and "}" as end of some text line. If...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
7
by: Trac Bannon | last post by:
When I load XML from a file into a dotNet XMLDataDocument, the UTF-8 codes are resolved but the 5 special XML entities are not. How can I force those 5 special character types to be translated?
3
by: orgelizer via AccessMonster.com | last post by:
I'm trying to enter some specific special characters (Ω, ±, ≥, ≤ for example) in Access. Knowing that ASCII should be ASCII, but with variations (the spice of life, right?), using the "Hold...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
2
by: jou00jou | last post by:
Hi, I have trouble using sscanf and fgets to check for overflow. I will post the assignment specification so I could help whoever would kindly like to offer his/her help. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.