package comefounderpubutil;
import javautilArrayList;
import javautilVector;
/
字符串处理工具类
@author xiewanzhi
/
public class StringFunction {
public static String convertFromStringArrayToStringBySymbol(String[] stringArray, char symbol) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < stringArraylength; i++) {
sbappend(stringArray[i]);
sbappend(symbol);
}
return sbtoString();
}
public static String[] convertFromStringToStringArrayBySymbol(String string, String symbol) {
Vector stringVector = convertFromStringToStringVectorBySymbol(string, symbol);
String[] stringArray = new String[stringVectorsize()];
for (int i = 0; i < stringVectorsize(); i++)
stringArray[i] = (String) (stringVectorelementAt(i));
return stringArray;
}
public static String[] convertFromStringToStringArrayBySymbolNO(String string, String symbol) {
Vector stringVector = convertFromStringToStringVectorBySymbolNO(string, symbol);
String[] stringArray = new String[stringVectorsize()];
for (int i = 0; i < stringVectorsize(); i++)
stringArray[i] = (String) (stringVectorelementAt(i));
return stringArray;
}
public static Vector convertFromStringToStringVectorBySymbol(String string, String symbol) {
Vector stringVector = new Vector();
String[] array = stringsplit(symbol);
for (int i = 0; i < arraylength; i++) {
stringVectoraddElement(array[i]);
}
return stringVector;
}
public static Vector convertFromStringToStringVectorBySymbolNO(String string, String symbol) {
Vector stringVector = new Vector();
String[] array = stringsplit(symbol);
for (int i = 0; i < arraylength; i++) {
stringVectoraddElement(array[i]);
}
return stringVector;
}
public static String convertFromStringVectorToStringBySymbol(Vector stringVector, char symbol) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < stringVectorsize(); i++) {
sbappend(stringVectorelementAt(i));
sbappend(symbol);
}
return sbtoString();
}
public static String fillString(String psStr, char psC, int psLen) {
if (psStrlength() > psLen) {
return psStrsubstring(0, psLen);
} else {
char[] vcTemp = new char[psLen];
for (int i = 0; i < psLen; i++) {
vcTemp[i] = psC;
}
String vsTemp = new String(vcTemp);
String vsResult = psStrconcat(vsTemp);
return vsResultsubstring(0, psLen);
}
}
public static String formatValue(double value, int sep, char ch, int round) {
return "";
}
public static String GB2Uni(String original) {
if (original != null) {
try {
return new String(originalgetBytes("GBK"), "ISO8859_1");
} catch (Exception e) {
eprintStackTrace();
return null;
}
} else
return null;
}
public static String Uni2GB(String original) {
if (original != null) {
try {
return new String(originalgetBytes("ISO8859_1"), "GBK");
} catch (Exception e) {
eprintStackTrace();
return null;
}
} else
return null;
}
public static String generateID(String pre, int value, int num) {
char chs[] = new char[num];
for (int i = 0; i < num; i++) {
chs[num - i - 1] = (char) (48 + value % 10);
value = value / 10;
}
return pretrim() + new String(chs);
}
public static String getTempStr() {
return StringvalueOf(SystemcurrentTimeMillis());
}
public static boolean isIncludeString(String psStr, String psS) {
int viPos = psStrindexOf(psS);
return viPos >= 0;
}
public static String replaceString(String psStr, String psS, String psD) {
int viPos = psStrindexOf(psS);
if (viPos < 0)
return psStr;
int viLength = psSlength();
StringBuffer vsValue = new StringBuffer();
while (viPos >= 0) {
vsValueappend(psStrsubstring(0, viPos));
vsValueappend(psD);
psStr = psStrsubstring(viPos + viLength);
viPos = psStrindexOf(psS);
}
vsValueappend(psStr);
return vsValuetoString();
}
public static String[] splitStringByToken(String vsStr, String symbol) {
String vsString[] = { "", "" };
int viPos1;
viPos1 = vsStrindexOf(symbol);
if (viPos1 < 0) {
vsString[0] = vsStr;
vsString[1] = "";
return vsString;
}
vsString[0] = vsStrsubstring(0, viPos1);
vsString[1] = vsStrsubstring(viPos1 + symbollength(), vsStrlength());
return vsString;
}
public static Vector convertFromStringToStringVectorByString(String string, String symbol) {
Vector stringVector = new Vector();
String vsStr = stringtrim();
String vsTemp = null;
String[] st = null;
while ((!vsStrequals("")) && isIncludeString(vsStr, symbol)) {
st = splitStringByToken(vsStr, symbol);
vsTemp = st[0]trim();
if (!vsTempequals(""))
stringVectoraddElement(vsTemp);
vsStr = st[1]trim();
}
if (!vsStrequals(""))
stringVectoraddElement(vsStr);
return stringVector;
}
public static String getTempStr(int length) {
String str = StringvalueOf(SystemcurrentTimeMillis());
return strsubstring(strlength() - length);
}
public static Vector convertFromStringToStringVectorByStringWithNull(String string, String symbol) {
Vector stringVector = new Vector();
String vsStr = stringtrim();
String vsTemp = null;
String[] st = null;
while ((!vsStrequals("")) && isIncludeString(vsStr, symbol)) {
st = splitStringByToken(vsStr, symbol);
vsTemp = st[0]trim();
stringVectoraddElement(vsTemp);
vsStr = st[1]trim();
}
if (!vsStrequals(""))
stringVectoraddElement(vsStr);
return stringVector;
}
public static String DelZeroForBM(String Bm, int Js, String Struct) {
int i, Len, Length;
Len = Bmlength();
Length = GetStructLength(Struct, Js);
if (Len >= Length) {
Bm = Bmsubstring(0, Length);
}
return Bm;
}
public static String FillZeroForBM(String Bm, String Struct) {
int i, Len, Length;
Len = Bmlength();
Length = GetStructLength(Struct, 0);
for (i = 0; i < Length - Len; i++) {
Bm += "0";
}
return Bm;
}
public static int getJsByCodingStruct(String code, String struct) {
int codeLength = codelength();
int structLength = structlength();
int tempLength = 0;
for (int js = 1; js <= structLength; js++) {
tempLength = GetStructLength(struct, js);
if (codeLength == tempLength)
return js;
}
return 0;
}
public static int GetStructLength(String Struct, int JS) {
int i, Length = 0;
String sub;
Integer ii;
if (JS == 0)
JS = Structtrim()length();
for (i = 0; i < JS; i++) {
sub = Structsubstring(i, i + 1)trim();
ii = Integerdecode("0x" + sub);
// Length += Integer parseInt(sub);
Length += iiintValue();
}
return Length;
}
public static String GetSubBMfromBM(String BM, String Struct, int SJS) {
String Res = "";
int Len;
Len = GetStructLength(Struct, SJS);
if (BMlength() >= Len)
Res = BMsubstring(0, Len);
return Res;
}
public static String FillZeroFromBegin(int num, int leng) {
return FillTagFromBegin(StringvalueOf(num), leng, "0");
}
public static String FillTagFromBegin(String num, int leng, String Tag) {
String Res = "", tempStr1 = "", tempStr2 = "";
tempStr1 = StringvalueOf(num);
for (int i = 0; i < (leng - tempStr1length()); i++) {
tempStr2 += Tag;
}
Res = tempStr2 + tempStr1;
return Res;
}
public static String ClearBMZero(String BM, String BMStruct) {
return ClearBMTag(BM, BMStruct, "0");
}
public static String ClearBMTag(String BM, String BMStruct, String Tag) {
int JSLen = BMStructlength();
String bm = "", ZERO, Tmp;
int Len;
for (int i = 1; i <= JSLen; i++) {
Tmp = BMStructsubstring(i - 1, i);
Len = IntegerparseInt(Tmp);
ZERO = RepeatChar(Tag, Len);
if (!BMstartsWith(ZERO)) {
bm += BMsubstring(0, Len);
BM = BMsubstring(Len);
} else
break;
}
return bm;
}
public static String RepeatChar(String c, int len) {
String Res = "";
for (int i = 0; i < len; i++) {
Res += c;
}
return Res;
}
/
key1=value1;key2=value2;key3=value3
@param inputString String
@param hashMap Map
/
public static void String2HashMap(String inputString, javautilMap hashMap) {
String[] keyValues = StringFunctionconvertFromStringToStringArrayBySymbolNO(inputString, ";");
String[] keyValue;
String key, value;
for (int i = 0; i < keyValueslength; i++) {
if (!""equals(keyValues[i])) {
keyValue = StringFunctionconvertFromStringToStringArrayBySymbolNO(keyValues[i], "=");
if (keyValuelength < 2)
continue;
key = keyValue[0];
value = "";
for (int k = 1; k < keyValuelength; k++) {
value += keyValue[k];
}
hashMapput(key, value);
}
}
}
/
@param hashMap
Map
@return String
/
public static String HashMap2String(javautilMap hashMap) {
Object[] keys = hashMapkeySet()toArray();
String key, value, keyValue = "";
for (int i = 0; i < keyslength; i++) {
key = (String) keys[i];
value = (String) hashMapget(key);
keyValue += key + "=" + value + ";";
}
if (keyValuelength() > 0) {
keyValue = keyValuesubstring(0, keyValuelength() - 1);
}
return keyValue;
}
/
@param value
String
@param mark
String
@return String[]
/
public static String[] split(String value, String mark) {
int index = valueindexOf(mark);
javautilList list = new ArrayList();
while (index >= 0) {
listadd(valuesubstring(0, index));
value = valuesubstring(index + marklength());
index = valueindexOf(mark);
}
listadd(value);
String[] rtn = new String[listsize()];
Systemarraycopy(listtoArray(), 0, rtn, 0, rtnlength);
return rtn;
}
public static void main(String[] args) {
String value = "a;;;; ";
String[] rtn = split(value, ";;");
Systemoutprintln(rtn);
}
}
package test;import javautil;/ 取得Map中的key的集合用的方法是keySet,返回的是Set,
取得Map中的value的集合用的方法是values,返回的是Collect。
值得一提的是,本题中是HashMap,如果改为TreeMap,keySet()方法返回的便会按着字母顺序排列,原因很简单,因为在TreeMap中即时按着这个顺序排列的。/public class Test_Map {
public static void main(String[] args) throws Exception {
Map map = new HashMap();
mapput("one", 1);mapput("two", 2);
mapput("three", 3);
//得到value的方法
Systemoutprintln("========得到value的方法========");
Collection c = mapvalues();
Systemoutprintln(c);
Iterator iter1 = (Iterator)mapvalues()iterator();
while(iter1hasNext()){
Systemoutprintln(iter1next());}//得到key的方法
Systemoutprintln("========得到key的方法========");
Collection s = mapkeySet();
Systemoutprintln(s);
Iterator iter2 = (Iterator)mapkeySet()iterator();
import javautilHashMap;
import javautilIterator;
import javautilMap;
public class Test {
public static void main(String[] args) {
//创建map
Map<String,Object> map=new HashMap<String,Object>();
//赋值
mapput("a", "b");
mapput("c", "d");
mapput("e", "f");
//输出该map的内容
getKeyAndValue(map);
}
/
得到map的key value
@param map 需要输出内容的map
/
private static void getKeyAndValue(Map<String,Object> map){
Iterator iterator=mapkeySet()iterator();
while(iteratorhasNext())
{
Object o=iteratornext() ;
//得到map中的所有键
String key=(String)o;
//得到map中的所有值
String value=(String)mapget(key);
//输出所需格式为:key:=value
Systemoutprintln( key+":"+"="+value);
}
}
Java servlet 将Map传到jsp中,用foreach获取map的值的方法:
以下是取值代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="javautil" %>
<%@ taglib prefix="c" uri=">
以上就是关于用C语言写一个类似于ATM机的程序,有开户(姓名,密码),存款,取款,查询余额,转账的功能,全部的内容,包括:用C语言写一个类似于ATM机的程序,有开户(姓名,密码),存款,取款,查询余额,转账的功能,、如何得到map中的KEY和VALUE、HashMap内容 输出到文本 格式key:=value等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)