Knowee
Questions
Features
Study Tools

Problem StatementWrite a program to remove  the characters from the first string which are present in the second stringInput FormatGiven two stringsOutput FormatPrint the updated first string

Question

Problem StatementWrite a program to remove  the characters from the first string which are present in the second stringInput FormatGiven two stringsOutput FormatPrint the updated first string

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for the problem:

def remove_chars(str1, str2):
    # Create a hash table to store characters of str2
    hash_table = set(str2)
    
    # Iterate over str1 and only keep characters not in hash_table
    str1 = [char for char in str1 if char not in hash_table]
    
    # Join the characters back into a string and return
    return ''.join(str1)

# Test the function
str1 = "hello"
str2 = "world"
print(remove_chars(str1, str2))  # Output: "he"

This program works by first creating a set (hash table) of all the characters in the second string. It then iterates over the first string and only keeps the characters that are not in the hash table. Finally, it joins the remaining characters back into a string and returns the result.

This problem has been solved

Similar Questions

Problem StatementWrite a program to remove the duplicate characters in the given stringInput FormatGiven a stringOutput Formatremove the duplicate characters and print the unique string

java program to remove special characters from the string

Now build a program to take string (combination of characters and digits) as input from the user and remove all the digits from the given string.Print the result as shown in the sample test cases.Sample Test CasesTest Case 1:Expected Output:str:·Hello123WorldString·after·removing·all·digits:·HelloWorldTest Case 2:Expected Output:str:·1234567890String·after·removing·all·digits:·Test Case 3:Expected Output:str:·PythonProgrammingString·after·removing·all·digits:·PythonProgramming

Mr. Vicky gave a task to his students. He gave two words, but there were some spelling mistakes found. In the first string, "!" denotes the misspelt word. The second string has the correct spelling of the first string. Create a Java application and help the students remove the "!" and replace it with the correctly spelled character.Requirements:-        Both the Strings must be of the same length. Otherwise, print "Length of the strings <String1> and <String2> does not match"-        Both the Strings must contain only alphabets and '!' symbol. Otherwise, print "<String> contains invalid symbols"-       If both the strings contain invalid symbols, print "<String1> and <String2> contains invalid symbols"-        The output must have the combined string without any symbolsAssume that space is allowed in between the words and assume that the second string always will have the correct spelt character of the misspelt first string in the respective positions.Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input/Output 1:Enter the first string!eadEnter the second stringrrrrread Sample Input/Output 2:Enter the first stringF!n! !utEnter the second string!i!d O!!Find OutSample Input/Output 3:Enter the first stringPo**t**nEnter the second String!!si!io!Po**t**n contains invalid symbols Sample Input/Output 4:Enter the first string!a!i!Enter the second stringV*l*dV*l*d contains invalid symbols Sample Input/Output 5:Enter the first stringpr!gra!!i!gEnter the second stringprogrammingprogramming Sample Input/Output 6:Enter the first stringC!rr!sEnter the second string!a!!yLength of the strings C!rr!s and !a!!y  does not matchSample Input/Output 7:Enter the first stringC%rr*Enter the second string&a%$yC%rr* and &a%$y contains invalid symbo

Write a program to remove all digit in given string.Below given is the program to remove all punctuation's in a string and print the result.import stringpunctuations = string.punctuationresult = " "str = "List - []\n tuple - ()\n Dictionary - {}\n Comment - #\n Multiply - *\n not - !\n and - &\n or - |\n format specifier - %\n String - " " $ @ ; : ' / + = " for i in str: if i not in punctuations: result = result + iprint("String after removing all Punctuation's:", result)Here,We are importing string module to know the list of punctuation's using string.punctuation. Then we compare punctuations in the given string with the string.punctuation module and remove them from the input string and print the resultant string. str variable contains input string. for clause to iterate over the list of characters in the input string. if condition to check if a punctuation of the input string exists in punctuation variable or not.Output:Set of punctuations in string.punctuation is: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~String after removing all Punctuation's is: List tuple Dictionary Comment Multiply not and or format specifier String Now build a program to take string (combination of characters and digits) as input from the user and remove all the digits from the given string.Print the result as shown in the sample test cases.Sample Test CasesTest Case 1:Expected Output:str:·Hello123WorldString·after·removing·all·digits:·HelloWorldTest Case 2:Expected Output:str:·1234567890String·after·removing·all·digits:·Test Case 3:Expected Output:str:·PythonProgrammingString·after·removing·all·digits:·PythonProgramming

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.