Ruby string manipulation, remove first 3 characters and add them to the end of the string -
mystring = "svn-myapplication" or mystring = "git-myapplication"
my desired output:
mystring = "myapplications(svn)" mystring = "myapplication(git)"
question: first 3 characters of string should moved last enclosed brackets , "-" should removed.
i tried this:
mystring.gsub('svn-','')+"(svn)"
svn might git, want use first 3 characters moved end "-" removed , brackets enclosed
a regular expression groups work well:
mystring.gsub(/^([a-z]+)-(\w+)/, '\2(\1)')
Comments
Post a Comment