关于文本编辑的问题,请高手们进来看看 参考一下TextArea的实现~呵呵 乱说的~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道java自己有没有实现,要不自己拆分字符串算了,也不会很麻烦,估计50行左右就能搞定了。 我写了一个简单的例子,把字符串转换成你所要求的样子,你可以看一看:public class StringConvert { public final static int d_rows = 4; public StringConvert() { } public String[] convert( String s , int rows) { if( null == s || 0 >= rows ) return null; String[] result = new String[rows]; try { for( int i = 0; i < rows ; i ++ ) { int j = 0; result[i] = ""; while( (i + rows*j) < s.length() ) { result[i] += s.charAt( i + rows*(j++) ); } if( 0 == result[i].length() ) break; //no more chars here } } catch ( Exception e ) { e.printStackTrace(); } return result; } /** * @param args the command line arguments */ public static void main(String[] args) { String source = null; int rows = StringConvert.d_rows; if( 0 == args.length ) { source = "hahahahaha, this is a test"; } else if ( 1 == args.length ) { source = args[0]; } else if ( 2 == args.length ) { source = args[0]; try { rows = (new Integer(args[1])).intValue(); } catch ( Exception e ) { System.out.println("variable error, illegal rows"); System.exit( 1 ); } } else { System.out.println("Use: java ts SourceString"); System.exit( 2 ); } System.out.println("***********rows =" + rows +"*****************"); System.out.println("***********original string*************"); System.out.println(source); System.out.println("****************************************"); System.out.println(); StringConvert sc = new StringConvert(); String[] result = sc.convert( source, rows); if( null == result) { System.out.println("Convert error"); System.exit( 3 ); } System.out.println("***********result string*************"); for( int i = 0; i < result.length ;i++ ) { if( null != result[i] ) System.out.println( result[i]); } System.out.println("****************************************"); } } JAVASE 图片按钮 byte string 转换的问题,请教教我 tomcat新手问题 本人初学 求助高手 用javadoc想到的几个问题(菜鸟问题) 初涉JAVA版,小生姓!@#$@#@,请大家多多关照!!! 有关javaScript ★★讨论:自学java的人怎么才能有实践经验?★★ java正则匹配html标签中的内容 小白求问,关于动态绑定的问题! 谁能告诉我COGNOS,SAS都是什么? 想学JAVA但是一点不懂,求助!
public class StringConvert {
public final static int d_rows = 4;
public StringConvert() {
}
public String[] convert( String s , int rows) {
if( null == s || 0 >= rows )
return null;
String[] result = new String[rows];
try {
for( int i = 0; i < rows ; i ++ ) {
int j = 0;
result[i] = "";
while( (i + rows*j) < s.length() ) {
result[i] += s.charAt( i + rows*(j++) );
}
if( 0 == result[i].length() )
break; //no more chars here
}
}
catch ( Exception e ) { e.printStackTrace(); }
return result;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String source = null;
int rows = StringConvert.d_rows;
if( 0 == args.length ) {
source = "hahahahaha, this is a test";
}
else if ( 1 == args.length ) {
source = args[0];
}
else if ( 2 == args.length ) {
source = args[0];
try {
rows = (new Integer(args[1])).intValue();
}
catch ( Exception e ) {
System.out.println("variable error, illegal rows");
System.exit( 1 );
}
}
else {
System.out.println("Use: java ts SourceString");
System.exit( 2 );
}
System.out.println("***********rows =" + rows +"*****************");
System.out.println("***********original string*************");
System.out.println(source);
System.out.println("****************************************");
System.out.println();
StringConvert sc = new StringConvert();
String[] result = sc.convert( source, rows);
if( null == result) {
System.out.println("Convert error");
System.exit( 3 );
}
System.out.println("***********result string*************");
for( int i = 0; i < result.length ;i++ ) {
if( null != result[i] )
System.out.println( result[i]);
}
System.out.println("****************************************");
}
}