Java is equivalent to Python’s string lstrip()?

I want to remove leading spaces from the string, but not trailing spaces - so trim () won't work I use lstrip () in Python, but I'm not sure if there is an equivalent in Java

for instance

"    foobar    "

Should be

"foobar    "

I also want to avoid regular expressions if possible

Is there a built-in function in Java, or do I have to create my own method to perform this operation? (and the shortest path I can reach)

Solution

You can do this in regular expressions:

"    foobar    ".replaceAll("^\\s+","");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>