0

指定された文字列からデータを抽出したいのですが、なんとかそれを行うことができましたが、いくつかの問題が発生しました。

次の 2 つの文字列を指定します。

"ESS23300RGR","Boorum & Pease 23 Series Columnar Book, Record, 300 Page, Black/Red (23-300-R)","UnbeatableSale, Inc (Amazon Marketplace)","180.80","6.09","http://www.amazon.com/gp/offer-listing/B000DLBVU4/ref=olp_page_next?ie=UTF8&shipPromoFilter=0&startIndex=15&sort=sip&me=&condition=new","http://www.amazon.com/gp/offer-listing/B000DLBVU4/ref=olp_page_next?ie=UTF8&shipPromoFilter=0&startIndex=15&sort=sip&me=&condition=new"
"WLJ36210WGR","Basic Round Ring View Binder, 362 Line, 3 Ring, 1" Capacity, 8-1/2" x 5-1/2" Sheet Size, White","Gov Group (Amazon Marketplace)","3.61","7.70","http://www.amazon.com/gp/offer-listing/B0006OF55A/ref=olp_seeall_fm?ie=UTF8&shipPromoFilter=0&startIndex=0&sort=sip&me=&condition=new","http://www.amazon.com/gp/offer-listing/B0006OF55A/ref=olp_seeall_fm?ie=UTF8&shipPromoFilter=0&startIndex=0&sort=sip&me=&condition=new"

これは私が使用した式です: regexChecker( "[\w\s&\(\)-^,]{3,}" , longString);

それを使用して、一部のセクションの一部として , と " を使用しているため、最初の文字列を完全に分離することができましたが、2 番目の文字列は分離できませんでした。

最初の文字列と同様に、2 番目の文字列からデータを抽出するにはどうすればよいですか?

抽出する必要があるデータは次のとおりです: SKU、名前、競合他社、価格、送料、URL、ソース URL

前もって感謝します。

4

2 に答える 2

3

試す :

String[] tabS = myLine.substring(1, myLine.lenght() -1).split("\",\"");

重要なものをすべて削除する"

于 2012-07-13T12:11:51.740 に答える
0

次のコードを確認してください。両方の入力文字列に対して望ましい結果が得られました。

StringBuilder testt = new StringBuilder("\"ESS23300RGR\",\"Boorum & Pease 23 Series Columnar Book, Record, 300 Page, Black/Red (23-300-R)\",\"UnbeatableSale, Inc (Amazon Marketplace)\",\"180.80\",\"6.09\",\"http://rads.stackoverflow.com/amzn/click/B000DLBVU4\",\"http://rads.stackoverflow.com/amzn/click/B000DLBVU4\"");

 Pattern varPattern = Pattern.compile(",\"", Pattern.CASE_INSENSITIVE);

 Matcher varMatcher = varPattern.matcher(testt);

 List<String> list = new ArrayList<String>();

 int startIndex = 0, endIndex = 0;
 boolean found = false;

 while (varMatcher.find()) {
  endIndex = varMatcher.start();
  if (startIndex == 0) {
   list.add(testt.substring(startIndex, endIndex));
  } else {
   list.add(testt.substring(startIndex + 1, endIndex));
  }
  startIndex = varMatcher.start();
  found = true;
 }
 if (found) {
  if (startIndex == 0) {
   list.add(testt.substring(startIndex));
  } else {
   list.add(testt.substring(startIndex + 1));
  }
 }
 for (String s : list) {
  System.out.println(s);
 }
}
于 2012-07-13T12:29:44.047 に答える