mam wyrażenie:Jak używać stosu do analizowania ciąg
String stringContent="{\\*\\listtable{\\list{\\listlevel{\\leveltext}{\\levelNumber}}}}"
Jak wybrać wartości wszystkich otaczających szelkami jeden po drugim, w każdym przejściu tak:
"{\\levelNumber}"
"{\\leveltext}"
"{\\listlevel{\\leveltext}{\\levelNumber}}"
"{\\list{\\listlevel{\\leveltext}}}"
"{\\*\\listtable{\\list{\\listlevel{\\leveltext}}}}"
Tak pory robiłem to:
public class StringExtracter {
public String stringofObject(Section parentSectionObject, String stringContent) {
Stack stack=new Stack();
String returnString = "";
char arr[] = stringContent.toCharArray();
for(int i=0;i<=arr.length;i++){
while(arr[i]!='}'){
if(arr[i]=='{'){
stringContent=stringContent.substring(i+1);
returnString=stringContent;
System.out.println(stringContent);
braces=true;
Section sectionObject=new Section(parentSectionObject,stringContent);
stack.push(arr[i]);
}
}
return returnString;
}
Ale problemem jest to, że nie wykrywa prawo }
tak. Jak powinienem to robić?
wyjścia już teraz:
\*\listtable{\list{\listlevel{\leveltext}{\fefw}}}}
\list{\listlevel{\leveltext}{\fefw}}}}
\listlevel{\leveltext}{\fefw}}}}
\leveltext}{\fefw}}}}
\fefw}}}}
Nie jestem pewien, co chce zrobić. Czym jest "Section parentSectionObject"? Czy chcesz utworzyć drzewo lub po prostu wydrukować wszystkie elementy "{..}"? – Pshemo
@Pshemo To cię obserwuje. Tak, tworzę strukturę drzewa dla wszystkich wyodrębnianych ciągów. – Identity1
'" {\\ * \\ listtable {\\ list {\\ listlevel {\\ leveltext}}}} "to faktycznie węzeł główny. i 'list' następuje, a następnie' listLevel' – Identity1