Search code examples
javavb6code-conversion

How to Convert Visual Basic Str() to Java code


I was wondering if there is a better implementation for converting the following VB6 snippets in Immediate window to Java:

? Format("002-", "")
-2
? Str("002-")
-2

My Java code scans through the string and if it sees a negative sign, converts the string to a negative integer, else positive. I would like to know if Java has a utility function which functions the same way as this.

A link to the Str function here.

Thanks!


Solution

  • I believe this is what you're looking for:

    VB6       Java
    ---       -----
    Str()     Integer.toString ();  # Convert integer to string
    ***       Integer.ParseInt ();  # Convert string to integer
    Format()  String.Format ();
    

    Here are some links: