Truncating Strings by Bytes

后端 未结 13 1970
醉酒成梦
醉酒成梦 2021-02-06 04:21

I create the following for truncating a string in java to a new string with a given number of bytes.

        String truncatedValue = \"\";
        String curren         


        
13条回答
  •  忘掉有多难
    2021-02-06 04:29

    String s = "FOOBAR";
    
    int limit = 3;
    s = new String(s.getBytes(), 0, limit);
    

    Result value of s:

    FOO
    

提交回复
热议问题