parseargs.java
来自「无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上」· Java 代码 · 共 42 行
JAVA
42 行
/** * Parse a string into tokens based on a sequence of delimiters * Given delimiters (single characters) d1, d2, ..., dn, this * class recognises strings of the form s0[d1s1][d2s2]...[dnsn], * where s<i-1> does not contain character di * This is unambiguous if all di are distinct. If not, strings * are attributed to the earliest possible si (so if the delimiters * are : and :, and the input string is foo:bar, then s0 is foo, * s1 is bar and s2 is null */package net.tinyos.packet;class ParseArgs { String tokens[]; int tokenIndex; ParseArgs(String s, String delimiterSequence) { int count = delimiterSequence.length(); tokens = new String[count + 1]; tokenIndex = 0; // Fill in the tokens int i = 0, lastMatch = 0; while (i < count) { int pos = s.indexOf(delimiterSequence.charAt(i++)); if (pos >= 0) { // When we finally find a delimiter, we know where // the last token ended tokens[lastMatch] = s.substring(0, pos); lastMatch = i; s = s.substring(pos + 1); } } tokens[lastMatch] = s; } String next() { return tokens[tokenIndex++]; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?