Example usage for java.lang String substring

List of usage examples for java.lang String substring

Introduction

In this page you can find the example usage for java.lang String substring.

Prototype

public String substring(int beginIndex, int endIndex) 

Source Link

Document

Returns a string that is a substring of this string.

Usage

From source file:Main.java

public static void main(String[] argv) {
    String str = "java2s.com";
    System.out.println(str.substring(1, 3));
}

From source file:MainClass.java

public static void main(String[] arg) {
    String place = "abcedfghijk";
    String segment = place.substring(7, 11);

    System.out.println(segment);/* ww  w . j a v  a 2s  . c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    String str = "this is a test";

    String sub = str.substring(10, 13);

    System.out.println(sub);/*from  ww  w  . j av a 2  s  .  com*/

    sub = str.substring(10);

    System.out.println(sub);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String laDate = "2014-06-15";
    String dateString = laDate.substring(8, 10) + "/" + laDate.substring(5, 7) + "/" + laDate.substring(0, 4);
    Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dateString);
    String dateFormat = "dd-MMM-yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, new Locale("en_US"));
    String tDate = sdf.format(date);
    System.out.println(tDate);/*from  w  ww  . j  a v a  2s. c o m*/

}

From source file:com.hp.test.framework.Reporting.TestPath.java

public static void main(String ar[]) throws IOException {
    URL location = Test.class.getProtectionDomain().getCodeSource().getLocation();

    String path = location.toString();
    path = path.substring(6, path.indexOf("lib"));
    String Logos_path = path + "ATU Reports/HTML_Design_Files/IMG";
    String Source_logs_path = path + "HTML_Design_Files/IMG";
    String Source_Framework_Logo_path = Source_logs_path + "/Framework_Logo.jpg";
    String Source_hp_logo_path = Source_logs_path + "/hp.png";
    String Source_reports_path = Source_logs_path + "/reports.jpg";
    File Target_dir = new File(Logos_path);
    File Source = new File(Source_Framework_Logo_path);
    FileUtils.copyFileToDirectory(Source, Target_dir);
    File Source_Reports = new File(Source_reports_path);
    FileUtils.copyFileToDirectory(Source_Reports, Target_dir);
    File Source_hp = new File(Source_hp_logo_path);
    FileUtils.copyFileToDirectory(Source_hp, Target_dir);

}

From source file:MainClass.java

public static void main(String[] args) {
    try {//w  w w .j  av a 2s  .  com
        Class c = Class.forName("java.util.ArrayList");

        Constructor constructors[] = c.getDeclaredConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.print(constructors[i].getName() + ": ");
            Class parameters[];
            parameters = constructors[i].getParameterTypes();
            for (int j = 0; j < parameters.length; j++) {
                String s = parameters[j].getName();
                s = s.substring(s.lastIndexOf(".") + 1, s.length());
                System.out.print(s + " ");
            }
            System.out.println("");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from w  w w.ja  v a  2  s .c  om
        Class c = Class.forName("java.util.ArrayList");

        Constructor constructors[] = c.getConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.print(constructors[i].getName() + ": ");
            Class parameters[];
            parameters = constructors[i].getParameterTypes();
            for (int j = 0; j < parameters.length; j++) {
                String s = parameters[j].getName();
                s = s.substring(s.lastIndexOf(".") + 1, s.length());
                System.out.print(s + " ");
            }
            System.out.println("");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String xmlFileName = "data.xml";
    String xPath = "//article/body/p";
    Document document = getDocument(xmlFileName);
    List<Node> nodes = document.selectNodes(xPath);
    for (Node node : nodes) {
        String nodeXml = node.asXML();
        System.out.println("Left  >> " + nodeXml.substring(3, nodeXml.indexOf("<ref")).trim());
        System.out.println(//from w  ww.  j  a  v a  2s . c  o m
                "Right  >> " + nodeXml.substring(nodeXml.indexOf("</ref>") + 6, nodeXml.length() - 4).trim());
    }
}

From source file:Main.java

public static void main(String[] args) {
    String query = "name==p==?header=hello?aname=?????lname=lastname";
    String[] params = query.split("\\?");
    Map<String, String> map = new HashMap<String, String>();
    for (String param : params) {
        String name = param.split("=")[0];
        String value = param.substring(name.length(), param.length());
        map.put(name, value);/*from   w  w w . j  a v a2 s  .  com*/
        System.out.println(name);
        if (name.equals("")) {
            value += "?";
        }
        System.out.println(value.replaceAll(" ", ""));
    }
}

From source file:UdpEchoClient.java

public static void main(String[] args) {
    InetAddress address;// ww w  . j  a va  2 s. c o  m
    try {
        address = InetAddress.getByName(args[0]);
    } catch (UnknownHostException host) {
        System.out.println(host);
        return;
    }
    DatagramPacket pack = new DatagramPacket(testString.getBytes(), testString.length(), address, 7);
    DatagramPacket incoming = new DatagramPacket(new byte[256], 256);
    DatagramSocket sock = null;
    try {
        Calendar start, end;
        sock = new DatagramSocket();
        start = Calendar.getInstance();
        sock.send(pack);
        sock.setSoTimeout(5000);
        sock.receive(incoming);
        end = Calendar.getInstance();
        String reply = new String(incoming.getData());
        reply = reply.substring(0, testString.length());
        if (reply.equals(testString)) {
            System.out.println("Success");
            System.out.println("Time = " + (end.getTime().getTime() - start.getTime().getTime()) + "mS");
        } else
            System.out.println("Reply data did not match");
    } catch (SocketException socke) {
        System.out.println(socke);
    } catch (IOException ioe) {
        System.out.println(ioe);
    } finally {
        sock.close();
    }
}