How to obtain a version number from a String?
16/05/2018 12:08
Hi all,
I'm trying to find a way to obtain the version number from this String,in this case, it should be 9:

Welcome to SUSE LINUX Enterprise Server 9 (i586) - Kernel (l).


I was thinking about regular expression, match the pattern and somehowget the version number.


I would really appreciate if any experts can give me a hand on this.

Thanks!

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
16/05/2018 12:08 - Thanks to both you for the replies, really appreciate it.


Anyway, these are the strings that I would expect (depends on whichLinux machine I run on):
Welcome to SUSE LINUX Enterprise Server 9 (i586) - Kernel (l).

Welcome to SuSE SLES 8 (powered by UnitedLinux 1.0) (i586)Red Hat Enterprise Linux AS release 3 (Taroon Update 3)Turbolinux EnterpriseServer 8.0 (Quattro)Red Flag Advanced Server release 4.1
Sometimes, the version is something like 9, and sometimes, is somethinglike 4.1Seems like the pattern is kinda hard to construct :)What do you think?

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
16/05/2018 12:08 - It depends on if the String information changes structure.


If it says relatively the same you could just do thisString version = aString.substring(40).split( )[0];
There might be a better way though.


If the first number is always the version number thenString version = null;String[] parts = aString.split( );for (int i = 0; i < parts.length; i++) { try { Integer.parseInt(parts[i]); } catch (NumberFormatException thrown) { continue; } version = parts[i]; break;}
However that may be inefficient due to the use of looped try-catchblocks, but should work.


Unfortunately, I am no expert with respect to regular expressions.



Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
16/05/2018 12:08 - Well you could use a regexp, provided you know what pattern to lookfor. What would you say it is in this case ? can't be just an integer(else 586 could be a version number).

So would it be an integer between spaces ? (what happens if you runinto a 9.3 version ?)That is the first thing to know : how do you define the version numberso this definition can be applied to any string you might encounter andenable to find the correct part.

Once you know that, building the regexp can be done (might be an uglyone, but you can describe almost any pattern using regexp)

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
16/05/2018 12:08 - If you Really Know you're running on a Unix flavor,you could try the `uname -r' command.



Source is Usenet: comp.lang.java.help
Sign in to add a comment

eDiscover
Helpforce eDiscover provides technical articles updated each dayHelpforce eDiscover RSS feed contains the latest technical articles in RSS
Click the logo to go back to the main page
Search eDiscover
  
Categories

Click an icon to go to that category

Helpforce eDiscover contains articles about Microsoft Windows Helpforce eDiscover contains articles about Apple products and MacOS Helpforce eDiscover contains articles about Linux and POSIX operating systems Helpforce eDiscover contains articles about Helpforce Helpforce has a large variety of technical information and articles for you to read Helpforce eDiscover contains articles about databases, MYSQL, SQL Server Oracle Helpforce eDiscover contains articles about Java, JVM and the JRE Helpforce eDiscover contains articles about the QNX operating system Helpforce eDiscover contains articles about Oracle Solaris and Open Solaris Helpforce eDiscover contains articles about RISC OS, Acorn and the BBC Micro Helpforce eDiscover contains articles about Amiga and AmigaOS

Type your comment into the box below