📄 supportclass.cs
字号:
//
// In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
// creates "support classes" that duplicate the original functionality.
//
// Support classes replicate the functionality of the original code, but in some cases they are
// substantially different architecturally. Although every effort is made to preserve the
// original architecture of the application in the converted project, the user should be aware that
// the primary goal of these support classes is to replicate functionality, and that at times
// the architecture of the resulting solution may differ somewhat.
//
using System;
/// <summary>
/// Contains conversion support elements such as classes, interfaces and static methods.
/// </summary>
public class SupportClass
{
//Provides access to a static System.Random class instance
static public System.Random Random = new System.Random();
/*******************************/
/// <summary>
/// The class performs token processing from strings
/// </summary>
public class Tokenizer
{
//Element list identified
private System.Collections.ArrayList elements;
//Source string to use
private string source;
//The tokenizer uses the default delimiter set: the space character, the tab character, the newline character, and the carriage-return character
private string delimiters = " \t\n\r";
/// <summary>
/// Initializes a new class instance with a specified string to process
/// </summary>
/// <param name="source">String to tokenize</param>
public Tokenizer(string source)
{
this.elements = new System.Collections.ArrayList();
this.elements.AddRange(source.Split(this.delimiters.ToCharArray()));
this.RemoveEmptyStrings();
this.source = source;
}
/// <summary>
/// Initializes a new class instance with a specified string to process
/// and the specified token delimiters to use
/// </summary>
/// <param name="source">String to tokenize</param>
/// <param name="delimiters">String containing the delimiters</param>
public Tokenizer(string source, string delimiters)
{
this.elements = new System.Collections.ArrayList();
this.delimiters = delimiters;
this.elements.AddRange(source.Split(this.delimiters.ToCharArray()));
this.RemoveEmptyStrings();
this.source = source;
}
/// <summary>
/// Current token count for the source string
/// </summary>
public int Count
{
get
{
return (this.elements.Count);
}
}
/// <summary>
/// Determines if there are more tokens to return from the source string
/// </summary>
/// <returns>True or false, depending if there are more tokens</returns>
public bool HasMoreTokens()
{
return (this.elements.Count > 0);
}
/// <summary>
/// Returns the next token from the token list
/// </summary>
/// <returns>The string value of the token</returns>
public string NextToken()
{
string result;
if (source == "") throw new System.Exception();
else
{
this.elements = new System.Collections.ArrayList();
this.elements.AddRange(this.source.Split(delimiters.ToCharArray()));
RemoveEmptyStrings();
result = (string) this.elements[0];
this.elements.RemoveAt(0);
this.source = this.source.Remove(this.source.IndexOf(result),result.Length);
this.source = this.source.TrimStart(this.delimiters.ToCharArray());
return result;
}
}
/// <summary>
/// Returns the next token from the source string, using the provided
/// token delimiters
/// </summary>
/// <param name="delimiters">String containing the delimiters to use</param>
/// <returns>The string value of the token</returns>
public string NextToken(string delimiters)
{
this.delimiters = delimiters;
return NextToken();
}
/// <summary>
/// Removes all empty strings from the token list
/// </summary>
private void RemoveEmptyStrings()
{
for (int index=0; index < this.elements.Count; index++)
if ((string)this.elements[index]== "")
{
this.elements.RemoveAt(index);
index--;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -