string的简单练习

主要用到以下函数

package dishiyitian;

public class lianxi {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        // text1();

        text2();

    }

    private static void text2() {

        // TODO Auto-generated method stub

        String name="fdfd;feit.texfd;hellow.yuyu;hellow.php";

        String name1=name.substring(0,1).toUpperCase();

        String name2=name.substring(1);

        System.out.println(name1+name2);

    }

    private static void text1() {

        // TODO Auto-generated method stub

        String name="fdfd;feit.texfd;hellow.yuyu;hellow.php";

        String[] name1=name.split(";");     //注意实现要求数组

        for(String n:name1)

        {

            if(n.startsWith("hellow"))

            {

                System.out.println(n);

                int i=n.lastIndexOf(".");

                System.out.println(n.substring(i));

            }

        }

    }

}

实现结果如下

hellow.yuyu

.yuyu

hellow.php

.php

Fdfd;feit.texfd;hellow.yuyu;hellow.php

猜你喜欢

转载自blog.csdn.net/zhouzhou_98/article/details/81229997