Click here to Skip to main content
15,888,026 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
need to create a parser so that a string containing intergers can be replicated, with the intergers changed as the user sees fit.

Example:

"Bob has 6 apples in 2 baskets"
"there are 2 baskets which have 6 of bobs apples"


just wondering how to go about this, ive been thinking for a few days now, need an other mind to come up with a layout.

so far ive got a drop down menu which can select either of the above strings, places them into a rich text box and the user can adjust either of the int values in their selected string.

Am i right in thinking the parser should break the string down, and each 'part' of the string should be held in seperate columns of a table?
So that when the user decides to changes the integers then the parser can check where, (if moved) the integer should be?
Please help... hpw would you approach this? Thanks you

Im really confused in how to handle such a situation.

Any help is very much appreciated.

Kind Regards Matt.

Edit.
Its not the parser im having trouble with, as i can create a procedure before entering to the table, so the parser runs over the user's entered string. its how to lay out form, any one done something similar that can advise?
Posted
Updated 1-Jun-13 2:24am
v4
Comments
Sagar H Upadhyay 1-Jun-13 8:35am    
Lot's of confusion, here. Can you just simply explain What will be as input and what you want as output..
I.E:- INPUT -> OUTPUT.

This seems like essay...
Sorry....
BBCokeley 1-Jun-13 8:46am    
Input>"Bob has 6 apples in 2 baskets"
"there are 2 baskets which have 6 of bobs apples" (either or)

output > "Bob has 6 apples in 2 baskets"
"there are 2 baskets which have 6 of bobs apples" (but user can change integer values, so parser can detect the white space increase ie "there are 12 baskets which have 6 of bobs apples" or "there are 2000 baskets which have 6958 of bobs apples" etc..

each time the numbers go above single figures, the parser would detect this (if statement) and increment the white space, just thinking of a way to allow the user to write this, like a text box or dropdown menu with just the integers as editable.

thanks for your reply

It is still not 100% clear to me what it is that you are after.

Would I be correct in my understanding that you need is a place holder? An equivalent of a readonly-variable that you would be able to "stuff" the new sentence structure with the appropriate place holder (variable)?

If so, will named regular expressions do?

If I am correct, then you may care to check out the article: http://www.codeproject.com/Articles/42304/Enhanced-String-Handling-III

Cheers,
Avi
 
Share this answer
 
Comments
BBCokeley 1-Jun-13 20:03pm    
@Avi Farah

thats exaclty what im trying to do, and have got a good idea in how to accomplish this, ill post in a few hours really tired now

thanks friend.
BBCokeley 1-Jun-13 20:09pm    
basically, someone will be injecting the said strings but changing the integer values, and i will be displaying the output (the 2 above strings) they can change the integer values but the string layout remains the same, (sql parser handles this) is there a way to auto update a text box (or similar) every 3 or so seconds so that the latest message is displayed?

this way a persistant update is always displayed..... display will be ordered by date time.
BBCokeley 1-Jun-13 20:13pm    
Once again, thank you for all your feedback and suggestions, it is very much appreciated, i am not an expert in codeing and all help will progress my career, as i am trying to further my career by making a persistant update window that will take the above formats no matter what it is fed through SQL server.

Kind regards
MAtt.
Well you need a very simple parser, actually. you might simply split the string using the space as separator and then, on the resulting array items, find the integers (a int.TryParsewould suffice) and keep track of their indices (amybe using another array or a list). This way, generating the required output would be trivial.
 
Share this answer
 
Comments
BBCokeley 1-Jun-13 8:52am    
@CPallini
Thank you for your reply, am i right in thinking what you mean is the strings 'white space' would be noticed if the number was single or double or even tripple figures (ie.. 2, 23, 221 etc..)

Thanks again.
The best ans as you need.
If you want to numbers from string just simply use regex.
See the following code block.
C#
Regex reges = new Regex(@"\d+");
Match match = regex.Match("test 66");

if (match.Success)
{
    Console.WriteLine(string.Format("RegEx found " + match.Value + " at position " + match.Index.ToString()));
}
else
{
    Console.WriteLine("You didn't enter a string containing a number!");
}

and also small amount of code will helps you.
C#
result = Regex.Match(FeatchFromStr, @"\d+").Value;

And in very old trick to solve this if you not want to use regex.
C#
string source = "str123";
string destination = string.Empty;
int FinalResult;
for (int i=0; i< source.Length; i++)
{
    if (Char.IsDigit(source[i]))
        destination += source[i];
}
if (destination.Length>0)
    FinalResult = int.Parse(destination);

Even linq can also help you.
C#
string Source = "3241k2h341k2341khlkhjl";
var Numbers = (from s in Source
           where char.IsDigit(s)
           select s).ToArray();
Console.WriteLine(new string(Numbers));
 
Share this answer
 
v3
Comments
BBCokeley 1-Jun-13 8:58am    
@Sagar H Upadhyay

Thank you again, i will test these and use both solutions in seperate programs, though im still confused on how to present the windows app...

Use text boxes, setup drop down menu for user to pick the string to edit etc..

Thanks you for your reply very helpful suggestion.
Sagar H Upadhyay 1-Jun-13 12:24pm    
If you still having any problem in developing window application, than I can help you if you want, you can contact me on my personal Id. which is usagar80@hotmail.com
BBCokeley 1-Jun-13 20:28pm    
It will be a layout that displays anything that is injected through ~SLQ server so that the latest message is displayed in one of the two formats, each format that is sent through sql server will be catergorized by an id field that will tell the display what it was sent as, (ie... "Bob has 6 apples in 2 baskets" (formatID1), or "there are 2 baskets which have 6 of bobs apples"(formatID2))

what i am trying to accomplish is displaying this in a read out (rich text box ... etc..)

the stored procedure (sql parser) can recognize and categorize each string and know which format to categorize with (specified in a table). so that the SQL server fed tables can be displayed by date/time in a persistent environment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900