0

I try to find a specific String in a Text File. The file looks like this:

2, 1, 'Ausbau der techn. Anlagen'

2, 2, 'Extension des installations techniques'

2, 3, 'Estensione delle istallazioni tecniche'

I try to find the text between the '' signs.

//Will be set automaticly after implementation.
    int project = 2
    int languageInteger = 1
    String findings = new File(usedPath)?.eachLine {
    
            it.substring((project+ ", " + languageInteger + ", "))
    
    }

This doesn't work. I've also tried with FindAll Closure or find. But I make some mistakes.

What should I do to find the text?

Community
  • 1
  • 1
CollinG
  • 67
  • 3
  • 11
  • This post explains [how to get String data between quotes](http://stackoverflow.com/questions/1473155/how-to-get-data-between-quotes-in-java). You'd have to replace the `"` in the regex with your `'` – Kaadzia Sep 24 '13 at 07:35
  • No, I know " ist not ' I've made in the solution below afterwards a replaceAll("'", "") that works fine now. – CollinG Sep 24 '13 at 10:35
  • I meant if you're going to use the Regex from the Tutorial: `Pattern.compile("\"([^\"]*)\"");` you'd have to replace the `"` ;-) – Kaadzia Sep 24 '13 at 10:37

1 Answers1

0

I found a Solution. It will not be the best, but it works.

    new File(usedPath)?.eachLine {

        if(it?.toString()?.startsWith(project+ ", " + languageInteger + ", ")){
            findings = it?.toString()?.split(project+ ", " + languageInteger + ", ")?.getAt(1)
        }
    }
CollinG
  • 67
  • 3
  • 11
  • Using `java.util.regex.Matcher` would be prettier. [Here's a Tutorial](http://tutorials.jenkov.com/java-regex/matcher.html) if you'd like to change your code. – Kaadzia Sep 24 '13 at 10:10