How to get English word alone from 100 words using Java program
I have 100 words. All 100 words are look lik开发者_如何学Ce this.
EnglishWord,EngMeaning,NumberofW… meaning,31
In that I want to retrieve EnglishWord
, e.g. Friendship
alone for 100 words by using Java program.
I am assuming you have a "body" (main string), containing a list of substrings and you want to retrieve any specific one substring from within.
This looks a lot like homework/exercise, so I'll avoid giving you a ready-to-roll answer, since you need to achieve a solution yourself for it to be of any value, but the general steps you will need are the following:
1:
Be able to separate each substring (entry) from the others (the base string) in an organized fashion. This can be done (for the string case), as @kylc said, with String's split function, which uses a REGEX (PATTERN) to define divisors (one or more), that then is/are used to divide the string into an array of multiple substrings.
String[] arrayOfEntries /*something to hold the result*/ = yourStringVar.split("," /*your split regex pattern*/);
NOTE: For more information on these, here are the links: String's split function, Pattern.
2:
Be able to acquire any specific entry withing an array of entries. This is best done with a function you can reuse for other works. You need to define a "target" (what/which is going to be acquired) and a "source" (group of entries to acquire "target" from).
All you have to do is loop the "source", and for each entry there, compare to "target" for a match; When a match is found, just return
it.
That's it! The rest is up to you!
精彩评论