Hi I have a requirement where, I need to check the string for the presence of = and &. If these two are present, then, Print, String is valid.
Else I need to print string is invalidHow to frame the design for this?
I don't exactly understand your requirements, because what you describe in text doesn't seem to match your examples.
You say: If = and & are present then the string is valid, otherwise it is invalid. Then you have an example: "Hellowrld" is valid. How can this be valid? It contains neither = nor &. And how does your requirement explain that "hello!world" is invalid?
First, make sure that you know exactly what valid or invalid means. If you can't exactly describe this, then you can't make a program that implements the rules. If the rules are clear, then you can probably do this with a regular expression.
Anu satya wrote:My requirement: 1. Only string-valid, string with = valid and String with & valid. Any special chars other than = & in the string is invalid.
As Campbell (and others) have said: you must learn to describe your requirements precisely.
The sentence "Only string-valid, string with = valid and String with & valid" could mean:
Any string with ANY character that is not a '=' or a '&' is invalid. which would make the string "HelloWorld" invalid because NONE of its characters are '=' or '&'.
You then go on to say:
"Any special chars other than = & in the string is invalid."
so, as Campbell said, you have to explain what "special chars" means (and don't forget about blanks (' ')).
When I was at school, back before the K-T extinction event, my prof used to say:
Imagine that you have to describe the problem to a 12-year old who has no knowledge of computers.
(tells you how long ago it was)
How would you explain it to him/her?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop