将java类转换为vb 2008应用程序

将java类转换为vb 2008应用程序,java,vb.net,bpel,Java,Vb.net,Bpel,我编写了一个Java类,它解析bpel文本文件,然后返回特定单词出现次数的计数。我想将其转换为VB2008表单应用程序,以便其结果显示在文本框中而不是控制台上。问题是VB2008缺少Scanner和StringTokenizer类,它们在我当前的Java类中。我不知道如何在VB2008中获得相同或更好的功能。有人能帮我转换这个类吗。多谢各位 Java类如下所示: import java.io.FileInputStream; import java.io.FileNotFoundExceptio

我编写了一个Java类,它解析bpel文本文件,然后返回特定单词出现次数的计数。我想将其转换为VB2008表单应用程序,以便其结果显示在文本框中而不是控制台上。问题是VB2008缺少Scanner和StringTokenizer类,它们在我当前的Java类中。我不知道如何在VB2008中获得相同或更好的功能。有人能帮我转换这个类吗。多谢各位

Java类如下所示:

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);         
}
}
您可以使用而不是StringTokenizer。对于您使用的扫描仪,应该是合适的替代品


由于解析的是XML文件,您可能会考虑使用.NET的XML解析功能代替字符串操作。

谢谢Heinzi,我尝试了StrueReals&S拆除法,但是我得到了不正确的结果。我想分割文件,然后计算序列的出现次数。知道怎么做吗?请参阅我的代码:Dim s As String=txtOpen.Text Dim arr As String=s.Split Dim searchTerm As String=用于arr txtSplit中的每个s.Multiline=True txtSplit.Lines=arr Next Dim matchQuery=arr中的word,其中word.ToLowerInvariant=searchTerm.ToLowerInvariant选择word Dim count As Integer=MATCHERY.counttxtwordoccurrences.Multiline=True txtwordoccurrences.Text=count.ToStringI目前没有VB编译器,因此我无法测试您的代码,但我注意到:尝试使用s.SplitNothing而不是s.Split,以便它在所有空白字符上进行拆分。另外,您的For-Each s循环没有意义-您不使用s!
    <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.