Microsoft Interview Question

Coding question: replace a char in a string with another string.

Interview Answers

Anonymous

Oct 2, 2017

# Python Code def replaceCharacter(s, characterToBeReplaced, replacement): retVal = "" for i in s: if i == characterToBeReplaced: retVal += replacement else: retVal += i return retVal print replaceCharacter("HowIsaPresidentYourFrat", "a", "SAMMY")

Anonymous

Aug 14, 2018

def replaceChar(s, ch, replacement): print(s.replace(ch, replacement))