bpel 텍스트 파일을 구문 분석 한 다음 특정 단어의 발생 횟수를 반환하는 Java 클래스를 작성했습니다. VB2008 Forms 응용 프로그램으로 변환하여 결과가 콘솔이 아닌 TextBox에 표시되도록했습니다. 문제는 VB2008에 현재 Java 클래스에있는 Scanner 및 StringTokenizer 클래스가 없다는 것입니다. VB2008에서 동일한 기능 (또는 그 이상)을 얻는 방법을 잘 모릅니다. 누군가가이 수업을 개종시키는 데 도움이 될 수 있습니까? 고맙습니다.Java 클래스를 vb 2008 응용 프로그램으로 변환
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class StringParser
{
private int ctrlFlowStructures;
private String filePath;
private ArrayList<String> activities;
final String[] ctrlFlowsArray={"sequence","if","while","repeatUntil","forEach", "pick","flow"};
public StringParser(String path)
{
filePath=path;
ctrlFlowStructures =0;
activities=new ArrayList<String>();
}
//count number of occurences of words in ctrlFlowStructureArray
public int countCtrlFlowStructures()
{
Scanner input=null;
StringTokenizer st;
String line=null;
String openingComment="!--";
String closingComment="--";
int c=0;
try
{
input=new Scanner(new FileInputStream(filePath));
}
catch(FileNotFoundException e)
{
System.out.println("Problem opening files.");
System.exit(0);
}
while(input.hasNextLine())
{
line=input.nextLine();
line.trim();
st= new StringTokenizer(line, " <,>\"",false);
String temp=null;
while (st.hasMoreTokens())
{
temp=st.nextToken();
//eliminate comments
if(temp.equals(openingComment)||temp.equalsIgnoreCase("documentation"))
{
c=1;
}
if(temp.equals(closingComment)||temp.equalsIgnoreCase("/documentation"))
{
c=2;
}
if(c==0||c==2)
{
for(int i=0;i< ctrlFlowsArray.length;i++)
if(temp.equalsIgnoreCase(ctrlFlowsArray [i]))
{
ctrlFlowStructures ++;
}
}
}
}
input.close();
return ctrlFlowStructures;
}
//display control flow structures
public void display()
{
int openingComment=0; //number of occurrence of an activity
for(int i=0;i< ctrlFlowsArray.length;i++)
{
for (int j=0;j<activities.size();j++)
{
if(ctrlFlowsArray [i].equalsIgnoreCase(activities.get(j)))
{
openingComment++;
}
}
if(openingComment>0)
{
System.out.println(ctrlFlowsArray [i]+" = "+openingComment);
openingComment=0;
}
}
}
public static void main(String[] args)
{
StringParser sp=new StringParser("c:\\MyFile1.bpel");
int a = sp.countCtrlFlowStructures();
System.out.println(" The number of control-flow structure(s) = " + a);
}
}
을 그리고이 구문 분석 된 MyFile1.bpel 파일의 코드입니다 :
<sequence>
<documentation>
The sequence includes several activities which are executed in lexical order.
</documentation>
<receive
name="start"
partnerLink="MyProcess"
operation="operation1"
portType="ns1:portType1"
variable="inputVar"
createInstance="yes">
<documentation>
The Receive activity makes the process to wait for the incoming message to arrive.
</documentation>
</receive>
<assign name="Assign1">
<documentation>
The Assign activity copies data from the input variable to the output variable.
</documentation>
<copy>
<from>$inputVar.inputType/ns2:paramA</from>
<to>$outputVar.resultType/ns2:paramA</to>
</copy>
</assign>
<reply
name="end"
partnerLink="MyProcess"
operation="operation1"
portType="ns1:portType1"
variable="outputVar">
<documentation>
The Reply activity returns a message from the process to the partner which initiated the communication.
</documentation>
</reply>
</sequence>
결과 :
다음과 같이자바 클래스입니다
The number of control-flow structure(s) = 1.
감사합니다. Heinzi, StreamReader 및 Split을 시도했지만 잘못된 결과가 나타납니다. 파일을 분할하고 "시퀀스"를 계산합니다. 어떤 생각을하는 방법? 내 코드를 참조하십시오 : 희미한들로 문자열 = txtOpen.Text 희미한를 편곡으로 문자열() = s.Split ("") 희미한 SEARCHTERM 문자열 =으로 "는"각 가 편곡에이야 txtSplit.Multiline = 진정한 txtSplit.Lines = 다음 희미한 matchQuery 편곡 = 단어에서 word.ToLowerInvariant() = searchTerm.ToLowerInvariant() 선택 단어 희미한는 정수 = matchQuery.Count() txtWordOccurences.Multiline = 진정한 txtWordOccurences.Text으로 간주 편곡에서 = count.ToString() –
user198934
지금 나와 함께 VB 컴파일러가 없으므로 코드를 테스트 할 수는 없지만 이것이 내가 알아 차린 것입니다. s.Split ("") 대신 s.Split (Nothing) , 그래서 그것은 * all * wh로 나뉘어집니다. itespace charaters. 추신. "For Each s"루프는 의미가 없습니다 - "s"를 사용하지 마십시오! – Heinzi