you are here: codestackercodes [RSS] → tag sample [RSS]

string manipulation

# using 'insert'


myString = "Paris in Spring" 
myString.insert 8, " the"  # returns "Paris in the Spring"


# using 'gsub' for remove non-alphabetic characters from a string


myString = "Only a test!!!" 
myString.gsub(/[^a-zA-Z|\s]/,'') # returns "Only a test"


# using 'gsub' for search & replace


myString = "I love ASP"
myString.gsub('ASP','Ruby') # returns "I love Ruby"

Displaying 1 Code