I have an api which returns a String in the following format: ACTNEW_38_0001,ACTO_57999 I need to extract the numerical values (57999, or 38_0001) but: 1: They can arrive in different order. 2: It can arrive only one of them. 3: It has to be lightweight. I roughly know how to do it. My actual code looks more or less like
Tag: substring
Trim from String after decimal places to 18 places in java – roundoff not required)
I am working on a legacy code where i have String field which hold some amount value, which should have only 18 char after decimal place, not more than that. I have achieved this like below – Is there any better way to do this ? Answer Use regex for a one line solution: See live demo.
Java Substring based on condtion
I’m pretty new to Java and I would like to know if there is an effective way of creating a substring based on conditions. Currently I am reading from a txt file and changing that txt file to a String format using BufferedReader. I am receiving several txt files but they all have the same format. The data that I
I want to return a formatted Phone Number with use substring but odd thing return
I’m new to java. why this don’t work ?? this must get something like this formatPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) and after that return (123) 456-7890 Thanks for the answers. Answer When using the toString(); method in a primitive type array the result is the location in the memory e.x “[I@1b28cdfa” If you want to
“String.substring(int, int) line: not available” causes error
Somehow my if loop using a substring to check a .txt file is causing problems. Without the if loop, everything works fine. But with it, it seems that an empty line in the text file is causing it to crash. It is working until the first empty line in the file, and then I get this error. What could I
How can I split string elements of an array and add them to another?
Using an array list of names, I am trying to split the first names and surnames using a for loop. The code works but when splitting the names using a substring it goes from 0-x (x being the space between the names) but it reads from 0 each time and adds each name multiple times until it completes. How can
Print out the numbers from the for loop
The Return type is void No input parameters Print out the numbers calculated results separated by a space using current number add the next number from 0 to (a+b). An example would be if the numbers …
How to extract words of constant length form a paragraph?
I’m trying to extract the words form a paragraph/string. I searched it out many where but didn’t find relative material. I want to extract words of length 4 from “I want to have alot of moneys when …
Split Word into Two and Check Existence in Comma Separated String Sequence
I have a string array for example: My goal is to split the first entry in the array in this case powerhouse into any two words and check them against the second entry, which serves as a dictionary of words. Here’s my implementation so far: I am stuck at the part where the first word has to be split. Should
Substring not equal to the string of the first character
I am struggling to figure out what’s wrong with my code. When the user input is “apple” I get that it doesn’t begin with a vowel. Answer You made a mistake using the substring method, you should say the start position in first parameter and the end position in second parameter : And now it works fine 🙂 :