searching strings

B

burchill

I am trying to write a kind of parser program, it is supposed to analyse
a guitar tab file (just a plain txt file). It should extract any chord
names in the tab file by trying match any text in the tab file with any
text in a list of chords in (another seperate file);

So far I have loaded both files into string variables and am trying to
search them using the regionMatches string method.

The chords (a list of all chords) file is in this format...

466644 Absus
466644 Absus4
466644 G#sus
466644 G#sus4
545445 A11+
545445 A9(#11)
545555 A7(#10)
545555 A7-10
557585 D7sus
557585 D7sus4
and so on...

The numbers aren't important (they represent the fingering to play that
chord). My main problem is that as you can see the chord names can vary
in length (can be anything from 1 character up to 9).

I am trying to write an algoritm that will take each chord name from the
chord string and then search for it in the tab string. Each chord name
starts on the 9th charcter on each line (including spaces as
chararcters) but they don't all end at the same character on each line.

Is there a way I can create a substring like this...

tab.subSTring(8, end of line);

Can I use the new line \n as a character to search for ?

Any help appreciated.
 
A

Andrew Thompson

Is there a way I can create a substring like this...

tab.subSTring(8, end of line);

Can I use the new line \n as a character to search for ?

Use a StringTokenizer or String.split to change the single String
to a String array, then loop through each array and ...

String chord = strings.subString( 8, strings.length() );

BTW - best group for people beginning Java is..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 
S

Scott Lopez

Look into regular expressions. There are good books on how to do this and
it may greatly simplify your task.
 
A

Anzime

Scott said:
Look into regular expressions. There are good books on how to do this and
it may greatly simplify your task.

e.g.

String tab = "466644 Absus";
String chordName = tab.substring( 8, tab.length() );
 
B

Babu Kalakrishnan

burchill said:
I am trying to write a kind of parser program, it is supposed to analyse
a guitar tab file (just a plain txt file). It should extract any chord
names in the tab file by trying match any text in the tab file with any
text in a list of chords in (another seperate file);

So far I have loaded both files into string variables and am trying to
search them using the regionMatches string method.

Instead of reading the list file as a single string and trying to split
it using a StringTokenizer as suggested, it would probably be easier to
use a BufferedReader and use its readLine method to read individual
lines into a List.
The chords (a list of all chords) file is in this format...

466644 Absus
466644 Absus4
466644 G#sus
466644 G#sus4
545445 A11+
545445 A9(#11)
545555 A7(#10)
545555 A7-10
557585 D7sus
557585 D7sus4
and so on...

The numbers aren't important (they represent the fingering to play that
chord). My main problem is that as you can see the chord names can vary
in length (can be anything from 1 character up to 9).

I am trying to write an algoritm that will take each chord name from the
chord string and then search for it in the tab string. Each chord name
starts on the 9th charcter on each line (including spaces as
chararcters) but they don't all end at the same character on each line.

Is there a way I can create a substring like this...

tab.subSTring(8, end of line);

Can I use the new line \n as a character to search for ?

Once you have each line as a separate string, s.subString(8) will give
you everything from index 8 (Character in position 9) onwards. You don't
really need to use the 2 argument variant of the substring method and
provide s.length() as the second argument.

BK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top