Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to pass strings for removeLetter() method, and return the the string with a single letter removed. After I have created a single random character in the end, how can I remove the single random character from the strings I have passed in 's1' and 's2'?

Maybe something like this:
String newWord = letters.charAt() - letters.charAt(charPos);


Full code:

C#
public class MyProgram
{
    public void start()
    {
        String s1 = removeLetter("MARVELLOUS");
        String s2 = removeLetter("TANGO");

        System.out.println("Letters removed: " + s1 + ", " + s2);
    }

    private String removeLetter(String letters)
    {

        int li = az.length();
        int ranChar = (int)(Math.random()*li);
        char charPos = letters.charAt(ranChar);


    }
}
Posted

You could convert the string to an ArrayList of char and then use Remove(charPos)
Then convert back to a string again with ToArray().
 
Share this answer
 
You could split the string into two substrings either side of the character you want removed. Then concatenate those two and return the newly created string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900