나는 방법 스트립 (가) 및 그 사용의 맥락이다찾기 여기에 "반대"또는 종료 문자
public String strip(String data, String tag)
{
...
}
@param data a string where all open symbols such as [({ have a matching close somewhere after them.
@param tag an opening symbol(such as "["
@return a substring of the contents between the first given opening and the last corresponding closing character- with both characters removed.
example:
strip("caca blah blah [ hb {} ((stuff){okay} vv]","[")
should return "hb {}((stuff)(okay) vv"
내 질문 - 나는 마음에 솔루션을하지만 난 방법을 찾기 위해 노력하고있다 가능한 모든 조합을 직접 코딩하지 않고 주어진 "반대"또는 닫는 문자를 찾으십시오. 어떤 종류의 속임수 또는 패턴 문자 코딩, 또는 어쩌면이 유틸리티 어딘가에 이렇게 있습니까?
HashMap<String, String> closingChar = new HashMap<>();
closingChar.put(")", "(");
closingChar.put("(", ")");
closingChar.put("}", "{");
closingChar.put("{", "}");
는 그런 다음 해당 문자를 찾을 수있는지도의 모든 문자를 조회 :
"첫 번째 주어진 시작과 마지막 해당 닫는 문자 사이"는 정말 원하는 것입니까? 'a [b] [c] d'는'b '[c']를 줄 것입니다. – Henry
저는 그 방법 자체에 관심이 없어요. 그 임의적인데, 지적 해 주셔서 고맙습니다. –