Topic DescriptionImplement a function that replaces a space in a string with "%20." For example, when the string is Are Happy, the replaced string is We%20are%20happy.
It would be easier to use Python, three ideas: 1, using Python's append function 2, using Python's split function 3, using strings to stitch code as follows:
#-*-Coding:utf-8-*-
"" "
Created on Sat Oct 17:20:46 2017
@author: Gb_xiao
mail:mingliumengshao@163 . com "" "" "
topic Description:
Please implement a function that replaces a space in a string with"%20 ".
For example, when the string is the We Are Happy, the character string after the replacement is
we%20are%20happy. "" "
def function1 (string): Result
= [] for
i in string:
if i = =" ":
result.append ("%20 ")
Else:
result.append (i) return
". Join (Result)
def function2 (string):
lists = String.Split ("") Return to
'%20 '. Join (lists)
def function3 (string): Result
= "" For
I in string:
if i = = "": result
= result + "%20"
else: result = result + I return result
def main ():
# string = "We Are Happy" Print
function1 ("We Are Happy") Print
function2 ("We Are Happy")
print Fu Nction3 ("We Are Happy")
if __name__ = = "__main__":
Main ()