Thread: Equivalent C# methods from Java

  1. #1
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Equivalent C# methods from Java

    I tried to look for these methods at the MSDN library, not sure which to select;

    What is the equivalent in C# to:

    Java charAt() method in a String- Chars property or Trim()

    and

    Java compareTo method in a String- is it Compare or CompareOrdinal in C#

    Like input on this

    ..Do this on break from reading AP exams
    Mr. C: Author and Instructor

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I could probably be more precise if you had listed what the Java methods do...

    The indexer property will give you a char a a specified position of a string.

    You can compare strings using operator ==.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Talking

    Ok: from the Java API

    charAt(int index)
    Returns the character at the specified index.

    compareTo(String anotherString)
    Compares two strings lexicographically.

    compareToIgnoreCase(String str)
    Compares two strings lexicographically, ignoring case differences.
    Mr. C: Author and Instructor

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    This page might help.

    You can access chars by using the indexer property:

    string x = "Test";

    x[2] = 'f';

    You can compare two strings by using either operator == or the Compare or CompareTo ( different interface implementantations, same result ) methods. If you need case insensitive comparison, try one of the many overloads of Compare.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    I went to the link you posted, earlier. I just did not find the examples clear enough. Thanks for the help.

    jc
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java for real-time applications
    By zacs7 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-26-2008, 06:34 AM
  2. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 09:09 AM
  3. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03:09 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  5. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM