Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String to Integer?

YnotYnot Member Posts: 113
[b][red]This message was edited by Ynot at 2002-10-14 3:30:5[/red][/b][hr]
Ehmm, its probably really easy in the end, but I have a question...

I have some data in the form: "name: result"
eg, "john doe:54"
:
:
:

I have:

String s = Console.readString();
String name = s.subString( 0, indexOf(':') - 1 );
String tRes = s.Substring( indexOf(':'), s.length() - 1 );

now I need to print it out in the form:
{54=john doe, ...}

My main problem is how to convert the result into an integer,
as it will be used later on for comparisons and sorting...

If you could post the code to convert 'String tRes' to 'int res'
it would be much appreciated.

Thanks in advance,
Ynot.



Comments

  • chamsterchamster Member Posts: 662
    : I have some data in the form: "name: result" eg, "john doe:54"

    I've just reinstalled my OS so the JVM is not set up yet which is why i can't give you the exact code until this evening. What you may do, and that's very easy, is to:[b][purple]
    - check the position of ":" in tString by
    int pos = tString.indexOf (':');
    - get a substring from (that position + 1) to the end of tString by
    String number = tString.subString (pos + 1);
    - convert to int by
    int id = Integer.parseInt (number);[/purple][/b]



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • YnotYnot Member Posts: 113
    Hey, thanks man!

    I could have sworn I tried that, but I'll giveit another go.

    I'll be lookin for more info a bit later... (when I'm not actually in
    the college building and I want to find out how to make it go as fast
    as possible!!!)

    Thanks dude,
    Ynot

    ____________________________

    Forever trust in who we are,
    And nothing else matters.
    -Metallica_
    ____________________________

  • chamsterchamster Member Posts: 662
    : I could have sworn I tried that, but I'll giveit another go.

    Ihear you. I've been there too.

    : I'll be lookin for more info a bit later... (when I'm not actually in
    : the college building and I want to find out how to make it go as fast
    : as possible!!!)

    ??

    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Andre YoungAndre Young USAMember Posts: 0

    ________ { http://forcoder.org } free ebooks and video tutorials about | Scratch, Visual Basic .NET, C, JavaScript, R, Swift, C#, Ruby, Visual Basic, Perl, Assembly, Go, PL/SQL, Java, PHP, Python, C++, Objective-C, MATLAB, Delphi Transact-SQL, Alice, Lisp, SAS, Fortran, ABAP, Rust, ML, Scala, Julia, Bash, Ada, Prolog, Clojure, Logo, Hack, Awk, COBOL, Crystal, Dart, VBScript, D, FoxPro, Kotlin, Apex, Scheme, Lua, LabVIEW, Erlang, F# | _____

Sign In or Register to comment.