From: eden li Date: 2007-04-15T15:54:14+09:00 Subject: Re: Not substitution \0, etc. in String.sub? Pass in a block instead: puts '%l'.sub(/%l/) { path } #=> C:\Artist\Album\01 Title.mp3 On Apr 15, 1:40 pm, "Jay McGavren" wrote: > I have a string that happens to contain '\0', which I need to > substitute for a %x flag a la sprintf. Unfortunately, the '\0' gets > substituted for the initial match. So, this: > > path = 'C:\Artist\Album\01 Title.mp3' > puts '%l'.sub(/%l/, path) > > ...gives me: > > C:\Artist\Album%l1 Title.mp3 > > I'm sure there's some way to disable the substitution that doesn't > involve contortions with escaping the backslashes, but I don't know > what it is. Anyone?