Advertisement
Guest User

Remove last item in string

a guest
Jul 20th, 2014
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. myString := "S523.WW.E.SIMA"
  2.  
  3. ; 1) Split it into the dot-separated parts,
  4. ;    then join it again excluding the last part
  5. parts := StrSplit(myString, ".")
  6. newString := ""
  7. Loop % parts.MaxIndex() - 1
  8. {
  9.     if(StrLen(newString)) {
  10.         newString .= "."
  11.     }
  12.     newString .= parts[A_Index]
  13. }
  14. msgbox % newString
  15.  
  16. ; 2) RegExMatch to extract everything up until the last dot
  17. RegExMatch(myString, "(.*)\.", newString)
  18. msgbox % newString
  19.  
  20. ; 3) RegExReplace to remove everything, starting with the last dot
  21. newString := RegExReplace(myString, "\.[^.]+$", "")
  22. msgbox % newString
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement