【发布时间】:2014-06-07 09:57:35
【问题描述】:
我在java中做了一个这样的程序:
class substr{
public static void main (String[]args){
int n=1;
String s1="";
String s2=" ";
while (n<=5){
System.out.println(s2.substring(n,5)+n+s1+n);
s1=s1+" ";
s2=s2+" ";
n++;
}
}
}
我无法在 ruby 中使用子字符串,所以我想知道是否有某种方法。我读过关于正则表达式的文章,但你不会在这样的程序中使用它。
【问题讨论】:
-
您正在寻找切片方法。 Google Ruby 字符串类切片。 PS 看看铲子运算符