正则表达式如何把String截取位定长的字符数组? 正则表达式怎么把一个String截取为长20个字符的字符串数组?比如"aaaa..."(40个)截取为长度为20个字符的两个字符串? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String.substring()不就可以吗?用正则干什么? String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"; Matcher matcher =Pattern.compile(regex).matcher(str); while(matcher.find()) System.out.println(Arrays.toString( matcher.group().toCharArray() )); /* [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t] [u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N] [O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7] */java传参的方式: A,只有值传递,B,既有值传递又有引用传递楼主选A还是B?上次我回复了你 现在打听一下楼主理解了么 regex = "\\w{20}" String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"; Matcher matcher =Pattern.compile(regex).matcher(str); while(matcher.find()) System.out.println(Arrays.toString( matcher.group().toCharArray() )); /* [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t] [u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N] [O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7] */ regex = "\\w{20}" 这个可以试试看 关于泛型类的设计 JAVA中有在某一时间自动触发的事件吗? 请问下大虾们:JSF调用javamail出错 想用"\n"实现换行,却变成了黑方框? java程序类的编译顺序和运行顺序一样吗? 设置自己的classloader的问题 近日开始学习struct,求一些相关资料!!! 谢谢!(中文尤佳) 为什么从sun的网站上下不了 j2sdk for linux????? classpath 在 JAVA 中调用 NT 里的 系统登陆检验 求java研发一面试问题 JAVA定义问题
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567";
Matcher matcher =Pattern.compile(regex).matcher(str);
while(matcher.find()) System.out.println(Arrays.toString( matcher.group().toCharArray() ));
/*
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t]
[u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N]
[O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7]
*/java传参的方式: A,只有值传递,B,既有值传递又有引用传递
楼主选A还是B?
上次我回复了你 现在打听一下楼主理解了么
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567";
Matcher matcher =Pattern.compile(regex).matcher(str);
while(matcher.find()) System.out.println(Arrays.toString( matcher.group().toCharArray() ));
/*
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t]
[u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N]
[O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7]
*/
regex = "\\w{20}" 这个可以试试看