This question already has answers here:
Parse any date in Java
(6 answers)
Closed 7 years ago.
I would like to know if there is a easy way to extract the first encountered date from a String in Java.
My program will analyse a lot of String texts, in different languages. These Strings can contain a date. Because of the languages (and the different sources), I have an awful lot of formats to take into consideration.
I first thought about Regex, making one regex for each format I could find... But there are an awful lot, for exemple "Month (d)d, yyyy" or "mm/dd/yyyy" or "dd-mon-yyyy"...
So I wanted to know if there is an easier way to extract date from a String maybe by using DateFormat, so I can convert the found date to "dd/mm/yyyy".
Thank you for your help. ^^
I think the best solution is to use a regex, but obviously you have to know all the possible patterns.
A (possible) way to do this is by means of machine learning: you can provide a set of representative examples and let the algorithm finds the patterns for you.
Your problem is really similar to the one addressed in this article.
You can try to use this webapp to find a good regular expression for you.
The main problem is that you have to provide significant examples.
I hope this will help you!
Related
This question already has an answer here:
Converting the format of the date in java
(1 answer)
Closed 1 year ago.
If I do:
ZonedDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE)
It returns a String, rather I'd like it to return a ZonedDateTime object. Is there a clean way of doing that. This is the obvious solution:
ZonedDateTime.parse(ZonedDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE));
Is there an easier way to do that? That just seems a little too verbose.
just use ZonedDateTime.now()
source: https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html#now--
This question already has answers here:
Naming Conventions For Class Containing Acronym
(3 answers)
Closed 9 years ago.
Instead of explaning I'll provide a simple and short example:
I would call a class that parses XMLs XMLParser. Sometime I run into problems,
e.g. I want to create a class that labels XMLs, but XMLLabeler seems kind of odd, because of the two same letters.
Since XML is a wide spread term it should be no problem to resolve this 'issue',
but for more complex acronyms this leaves a bad taste.
How would you handle these kind of things? Stricty applying camel case? I. e. XmlParser, XmlLabeler? Are there any naming conventions for acronyms in class names?
Camel Case (XmlParser) is the preferred way because it is easier to read
This question already has answers here:
How to convert number to words in java
(31 answers)
Closed 9 years ago.
I have an amount with different currencies, I want to convert an amount into words.suppose if i have a number 1000000, i have to print it for "Rupees ten lakh only" for india, "Dollar one million only" for usa etc...
Any suggestions would be great.
Thanks in advance,
Msn
I'm going to take a stab in the dark and assume you're talking about String and int data types.
To append the value of the int type onto the String use the String's method valueOf, for example:
String formattednumber = "$" + String.valueOf(amount);
In the future please provide more information to exactly you want and what you have tried, also code would be helpful.
If you need to print numbers as words then this might be helpful.
same logic can be used to append currency name.
hope that helps.
This question already has answers here:
Does Java have support for multiline strings?
(43 answers)
Closed 7 years ago.
For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example:
BufferedWriter buffW = new BufferedWriter(fileW);
buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>");
This is mess a code, I want to write a clean such as PHP can do, but can't find on Java alternative way as example:
<?php
$mystring = <<<EOT
This is some PHP text.
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;
?>
Is there a heredoc equivalent in Java?
No, there is no direct heredoc alternative in the Java programming language.
Check this similar question.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Raw Strings in Java?
In C# there is such a thing as # ("at sign") that can be put before string if forbidden symbols occurs. For example:
#"a\b\c"
In java I have to put backslashes
"a\\b\\c"
Is there any way in Java to make this easier?
Another way may be use equvivalent code for the symbols you want to escape.
Not really. I have made the transition not long ago and at first was constantly looking for "what is C#'s equivalent in Java for xyz?"
This is sometimes helpful but mostly frustrating. C# is a much more advanced language than Java and it will take a long time for Java to catch up.
You get used to it over time :-)