Skip to content
Advertisement

Tag: string

Java – splitting files by newline

How can I split file by newline? I’ve attempted to split by doing line.split(“\r?\n”) – but when I try printing the 0th index I get the entire file content when I was expecting just the first line. but if I try printing the result at index 0 I get the entire file content, when I expected to get just the

How can I get a special part in a string in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I have to read commands from a file I have and take necessary actions according to each command. I was able to find out the

Remove every space EXCEPT leading spaces

I need to remove every spaces from a String EXCEPT leading spaces. I have some strings that look like this : And I am trying to achieve this : That’s like a reverse trim(). What’s the most efficient way to go about it ? Answer You can use replaceAll with this regex (?<=S)(s+)(?=S) like this : Examples of input &

Converting String number words to just String number:Java

I’m a beginner coder trying to work on converter for words which should work that way:Input= “zero;six;eight;two” Output = “0682”. But in my case the output I get is “0282”. Are there any solutions to that? Or like maybe I should program differently?. I found that LinkedLists or HashMap could work, if so could you show how? Answer You should

How to skip a leading string when scanning text file?

I’m making a program that draws a basic image using instructions from a text file. The format for the instructions is: and this is my code: this is giving a NoSuchElementException. I’m assuming it’s because the fwidth and fheight are taking the leading strings as ints but i can’t figure out how to get the scanner to skip the strings

Advertisement