Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# String Algorithm

Greenhorn
Posts: 14
Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}

ali zaid
Greenhorn
Posts: 14

ali zaid wrote:Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}

String s="{([]),([]),([])(,[])}";
without using pattern matcher

Marshal
Posts: 5623
387
1. String is equal (method from String class) to yours specified?
2. String length is same as your specified pattern and contains (method from String class) it?
3. Starts with (method from String class) your pattern and contains space afterwards.
4. Ends with (method from String class) your pattern and has space in front of it.
5. Find first occurrence of space character, then find consequent space character, and check if such substring between spaces is equal to your pattern.
6. Find first occurrence of space character, then check if further substring contains your pattern, and then ensure it is the end of string.

I guess what I'm trying to say is, what are the requirements? One sentence isn't enough as explanation.

lowercase baba
Bartender
Posts: 12620
50

ali zaid wrote:Hi

How to write string algorithm to determine where or not the string match this pattern
String s={([]),([]),([]),([])}

That is not a pattern, that is an example.  If i said "how do I write a method that finds numbers like 2?"  you'd ask "do you mean even? prime? single digits?  integers?"

There are many, many ways to interpret a single example.  you need to tell us exactly what you mean.

ali zaid
Greenhorn
Posts: 14

Liutauras Vilda wrote:1. String is equal to yours specified?
2. String length is same as your specified pattern and contains (method from String class) it?
4. Starts with your pattern and contains space afterwards.
5. Ends with your pattern and has space in front of it.
3. Find first occurrence of space character, then find consequent space character, and check if such substring between spaces is equal to your pattern.
4. Find first occurrence of space character, then check if further substring contains your pattern, and then ensure it is the end of string.

I guess what I'm trying to say is, what are the requirements? One sentence isn't enough as explanation.

for example

m1("([1]");///this should print missed   )
m1("([1)");///this should print missed ]

m1("([2]) ([3])) . //this should print missed ,

Liutauras Vilda
Marshal
Posts: 5623
387
Again. Not clear at all.

What is that bit {([]),([]),([]),([])} ? String which you are looking or something else?

Looking to your latest post, all became even more unclear.

Liutauras Vilda
Marshal
Posts: 5623
387
Would be clearer if you'd say:
1. Every sequence needs to be enclosed in {}.
2. Every numeric value needs to be enclosed in [], which itself enclosed in ().
3. If there are more than one numeric value in such sequence, after the () supposed to be a comma and other numeric value needs to satisfy rule number 2.

This is something what we'd expect to hear from you.
For such task you'd need to write your own parser which might be quite complicated as I've listed only 3 rules, but there would be most likely more. you should know them before you start any coding.

Liutauras Vilda
Marshal
Posts: 5623
387

ali zaid wrote:m1("([1]");///this should print missed   )

What this should print?