How to make a program that replaces the first letter of every word with "sn"?

Home » Programming & Design » How to make a program that replaces the first letter of every word with "sn"?
Programming & Design No Comments

So i need something that replaces every first letter with "sn" and then afterwords it adds "(snail "original word")"

Best Answer:

Annabeth: string = "Hello World, My name is…";
out = string.replace(/\b\w/g, "sn") + "snail";

// out: snello snorld, sny sname sns…
// RegEx: \b matches beginning of word
// RegEx: \w matches a letter
// RegEx: /\b\w/g matches the first letter of every word

Other answer:

Here's an example program written in Python 3. Didn't want it in Python? Tell us which language you're using!

def replace(word, letters):
… return letters+word[1:]

sentence = "The quick brown fox jumps over the lazy dog."
# create list of words
words = sentence.split()
for word in words:
… word = replace(word, "sn")
… print (word, end=' ')

#Note: I've used "… " to show indentation (which Y!A removes). Replace with tabs or spaces.

Hi, Annabeth,

You failed to mention what programming language you are using. That should have been the first word of your headline (usually followed by a colon).

In any case, you should always show examples of specific input and output and you should always show us an attempt to write the program yourself. After all, your teacher thinks you are supposed to be capable of doing this on your own. This forum is not intended to do help you cheat by doing your whole assignment for you.