Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default friend... A doubt in string concept

    friend.... dis is kArtik... a very very smAll doubt....:)
    im comparing two strings..... sAy str1,str2.
    if any chArActer of str1 mAtches to str2, im going to delete that chAracter from both strings.....
    eample-
    befor execution-
    str1=ghjm
    str2=mjfg

    after execution-
    str1=gh
    str2=f

    how could i Acheive dis.....? plz send me code, And specify Appropriate string method to use in our code....:) thankx...

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    String.charAt()
    And read that: How To Ask Questions The Smart Way
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by u&me@javaforums View Post
    friend.... dis is kArtik... a very very smAll doubt....:)
    im comparing two strings..... sAy str1,str2.
    if any chArActer of str1 mAtches to str2, im going to delete that chAracter from both strings.....
    eample-
    befor execution-
    str1=ghjm
    str2=mjfg

    after execution-
    str1=gh
    str2=f

    how could i Acheive dis.....?
    with the replace method? See the String API docs.
    plz send me code,
    No.
    And specify Appropriate string method to use in our code....:) thankx...
    I already did (at least part of them and one possible way, there are more and others), and why would you need this if somebody had already done your work for you and sent you the code?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by u&me@javaforums View Post
    how could i Acheive dis.....? plz send me code, And specify Appropriate string method to use in our code....:) thankx...
    I don't understand that remark: if someone else sends you the code it is that other person's code, not 'our code', neither would it be your achievement, it would be the achievement of that other person.

    kind regards,

    Jos

  5. #5
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    I made it for you, you probaly won't understand a shit of it because you have to learn it yourself. But it was good for my practice.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication4;
    
    /**
     *
     * @author Leerling
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String str1="Hey there";
            String str2="Hello there";
            System.out.println(str1.replace("Hey there", "Goodbye"));
            System.out.println(str2.replace("Hello there", "Try to learn java yourself"));
        }
    
    }
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  6. #6
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Java Code:
    String str1="Hey there";
    String str2="Hello there";
    System.out.format("\tBefore%n---------------------------%nstr1 = %s%nstr2 = %s%n%n\tAfter%n---------------------------%nstr1 = %s%nstr2 = %s%n",str1,str2,str1.replaceAll("[" + str2 + "]", ""),str2.replaceAll("[" + str1 + "]", ""));
    intentionally made it bombast.

    Java Code:
    	Before
    ---------------------------
    str1 = Hey there
    str2 = Hello there
    
    	After
    ---------------------------
    str1 = y
    str2 = llo
    Last edited by Lil_Aziz1; 01-15-2010 at 01:18 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  7. #7
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    what was wrong with my code?
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Said the blind to his deaf guide.

  9. #9
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Quote Originally Posted by coltragon View Post
    what was wrong with my code?
    He's trying to delete similar characters within two Strings.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  10. #10
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    I think you mean

    after execution-
    str1=h
    str2=f

    if character 1 == 1 || 2 || 3 || 4, ...delete .

    Idk the exact code but just follow that
    11th Grade | Beginner Programmer | Looking into College

Similar Threads

  1. Embarrisingly simple from "a friend"
    By v6g in forum New To Java
    Replies: 5
    Last Post: 11-25-2009, 11:48 PM
  2. Interface concept
    By r.srimathi in forum AWT / Swing
    Replies: 5
    Last Post: 01-28-2009, 04:25 PM
  3. mail concept
    By indirani in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 01:30 PM
  4. mail concept
    By thamizhisai in forum Advanced Java
    Replies: 4
    Last Post: 04-11-2008, 07:19 AM
  5. string doubt
    By boy22 in forum New To Java
    Replies: 3
    Last Post: 08-02-2007, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •