Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.UnsupportedEncodingException;

public class Main {

    public static String getNewString(String str) {
        byte[] data = str.getBytes();
        int index = data.length;
        for (int i = 0; i < data.length; i++) {
            if (data[i] < 48 || data[i] > 57) {
                index = i;
                break;
            }
        }
        byte[] temp = new byte[index];
        System.arraycopy(data, 0, temp, 0, index);
        String res;
        try {
            res = new String(temp, "GBK");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
        return res;
    }
}