merlin
merlin

Reputation: 3

How do I strip the characters from this string?

"/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv

to this:

  /system/uploads/000/000/001/original/1/1.flv

Upvotes: 0

Views: 123

Answers (3)

Mike Lewis
Mike Lewis

Reputation: 64137

str = "/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv"
chopped = str.sub(/.*\/public/, "") #=> "/system/uploads/000/000/001/original/1/1.flv" 

This will remove everything to the left of public (including /public). This way your code isn't specific to one location, but rather it is more portable in that you can have anything in front of /public, and it will still strip the characters.

Upvotes: 2

Luixv
Luixv

Reputation: 8710

You should specify in which language. Using sed is trivial.

echo "\"/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv" | sed -e 's-\"/home/chief/project/public--'

Upvotes: 0

Dean Barnes
Dean Barnes

Reputation: 2272

s = "/home/chief/project/public/system/uploads/000/000/001/original/1/1.flv"
s.sub("/home/chief/project/public", "")

This should do the trick.

Upvotes: 0

Related Questions