473,386 Members | 1,715 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,386 software developers and data experts.

generating strings

I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?
Jul 22 '05 #1
7 1858
Eddie wrote:
I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
Usually with the help of 'sprintf' function. Your "pattern" is just
the format string you need to create.
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?


One may say that there is an algorithm for everything, all you need
to do is to find it.

Read about 'for' loops and 'sprintf' function.

Also, read the FAQ. Especially section 5.

Victor
Jul 22 '05 #2
Eddie wrote:

I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?

--
Karl Heinz Buchegger, GASCAD GmbH
Teichstrasse 2
A-4595 Waldneukirchen
Tel ++43/7258/7545-0 Fax ++43/7258/7545-99
email: kb******@gascad.at Web: www.gascad.com

Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
Jul 22 '05 #3
Eddie wrote:

I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?


I would start with dividing the pattern into 3 parts
a prefix
the repeat part
the rest up to the right end

eg. your given pattern [0-3]mid[4-7]end divides into

Prefix: empty
repeat part: [0-3]
rest: mid[4-7]end
function PrintPattern( string prefix, string pattern )

divide pattern into prefix_now, repeat part and rest
catanate the prefix_now to the passed prefix

if the repeat part is empty
print catanate( prefix, rest )
else
do a loop over the range of the repeat part
create a temporary string which consists of
the prefix and add the next character from the range

PrintPattern( temporary, rest )

end function

So this becomes a recursive algorithm. You might need to
tweak the above a little bit but basically that should be it.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #4
Karl Heinz Buchegger wrote:
Eddie wrote:

I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?


I would start with dividing the pattern into 3 parts
a prefix
the repeat part
the rest up to the right end

eg. your given pattern [0-3]mid[4-7]end divides into

Prefix: empty
repeat part: [0-3]
rest: mid[4-7]end
function PrintPattern( string prefix, string pattern )

divide pattern into prefix_now, repeat part and rest
catanate the prefix_now to the passed prefix

if the repeat part is empty
print catanate( prefix, rest )
else
do a loop over the range of the repeat part
create a temporary string which consists of
the prefix and add the next character from the range

PrintPattern( temporary, rest )

end function

So this becomes a recursive algorithm. You might need to
tweak the above a little bit but basically that should be it.

Thanks its good for a start, I will try to write this, it seems loking
easy now.
Jul 22 '05 #5
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
Eddie wrote:
My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end

I would start with dividing the pattern into 3 parts
a prefix
the repeat part
the rest up to the right end

eg. your given pattern [0-3]mid[4-7]end divides into

Prefix: empty
repeat part: [0-3]
rest: mid[4-7]end
function PrintPattern( string prefix, string pattern )

divide pattern into prefix_now, repeat part and rest
catanate the prefix_now to the passed prefix

if the repeat part is empty
print catanate( prefix, rest )
else
do a loop over the range of the repeat part
create a temporary string which consists of
the prefix and add the next character from the range

PrintPattern( temporary, rest )

end function

So this becomes a recursive algorithm. You might need to
tweak the above a little bit but basically that should be it.


This is good for the general case, especially when you want the user to be
able to enter a string like "[0-3]mid[4-7]end" or anything else with any
number of repeating parts, then you generate the strings.

But there is a simpler algorithm:

for (int i=0; i<=3; ++i) {
for (int j=4; j<=7; ++j) {
char buffer[some big number];
sprintf("%dmid%d", i, j);
or instead of the above 2 lines use ostringstream and <<;
}
}
Jul 22 '05 #6
"Siemel Naran" <Si*********@REMOVE.att.net> wrote...
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
Eddie wrote:

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end

I would start with dividing the pattern into 3 parts [...]


This is good for the general case, [...]
But there is a simpler algorithm:
[...]


I see somebody is just itching to do somebody else's homework, eh?
Not enough problems to solve at work, I take it... Or has it been
a long documentation-writing week with almost no coding? <g>
Jul 22 '05 #7
Eddie wrote:
I searched with my problem but with no results :(

My question is: how can I generate string, having only simple pattern,
like, [0-3]mid[4-7]end
For example tyis pattern should reproduce strings like:

1. 0min4end
2. 0min5end
3. 0min6end
4. 0min7end

5. 1min4end
6. 1min5end
7. 1min6end
8. 1min7end

9. 2min4end
10. 2min5end
11. 2min6end
12. 2min7end

13. 3min4end
14. 3min5end
15. 3min6end
16. 3min7end

Is there a alghoritm for it, how can I begin with making this?


To put things in perspective ( or to make things complicated a little
bit) google for 'regular expressions'. You will have a better idea of
implementing it. ( or even a considerable superset of the given problem)

--
Karthik
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
7
by: Mary | last post by:
Hi, I need some assistance with a query. To be honest, I'm not even sure it can be done. I'll try to keep the information limited to only what's relevant to what I have and what I am trying to...
3
by: Eddie | last post by:
I searched with my problem but with no results :( My question is: how can I generate string, having only simple pattern, like, midend For example tyis pattern should reproduce strings like: ...
2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
9
by: =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= | last post by:
With regexps you can search for strings matching it. For example, given the regexp: "foobar\d\d\d". "foobar123" would match. I want to do the reverse, from a regexp generate all strings that could...
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
6
by: Mike P | last post by:
I am generating 12 random strings and my code works fine when I step through, but when I then let it run without stepping through and populate a listbox with the array I am building, I get the same...
6
by: py_genetic | last post by:
Hi, I'm looking to generate x alphabetic strings in a list size x. This is exactly the same output that the unix command "split" generates as default file name output when splitting large...
6
by: Lloyd Sheen | last post by:
Perhaps I have missed something but what I would like to do is have a more "controlled" method of generating HTML from a web service. I can create items using HtmlTable, HtmlTableRow, and...
4
by: dhinakar_ve | last post by:
Hi All, I am writing a function to generate the strings based on a pattern. For example A will generate A1, A2 and A3. If the pattern is A then it will generate the strings A11, A12, A21,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.