Minusing 3 characters from the end of a string in Java
本问题已经有最佳答案,请猛点这里访问。
我有一个字符串ocustomerordernumber,我正在将值传递给icustomerordernumber。我想删除此ICustomerOrderNumber中的最后3个字符,但无法使其正常工作。我得到的错误是它不喜欢-。
代码:
1 2 | oCustomerOrderNumber = iCustomerOrderNumber.trim() - (iCustomerOrderNumber.length() -3); |
例子。icustomerordernumber是1234567我希望ocustomerordernumber是1234。
For getting a portion of a string you can use substring method and
here you can define from where until where you want to fetch from any
String:
号
1 | iCustomerOrderNumber.substring(0, iCustomerOrderNumber.length()-3); |
ocustomerordernumber=icustomerordernumber.substring(0,(icustomerordernumber.length()-3));