in reply to How to remove an apostrophe?

Your code works:

$fullName = "c:\\path\\boo's"; @string_parts = split(/\\/,$fullName); foreach $part (@string_parts){ $newName = $part; } $newName =~ s/\'//g; print("$newName\n"); __END__ output ====== boos

Are you sure it's an apostrophe and not a (unicode?) character that looks like one? Or maybe a backtick (`)?

By the way,
foreach $part (@string_parts) { $newName = $part; }
can be reduced to
$newName = $string_parts[-1];

Replies are listed 'Best First'.
Re^2: How to remove an apostrophe?
by sfhazel (Novice) on Oct 12, 2005 at 18:40 UTC

    It is pulled from the filename: "00_te'st.jpg"

    So, I'm sure it's not a backtick. If it is unicode, what would you suggest to fix it?

    Also, thank you for simplifying that other peice of code. I'm still in the "get the thing to work" phase of development. hehe.

      Find out what character it is using the snippet below, then use \x{####} instead of an apostrophe in the regexp, where "####" is the number printed by the snippet below).

      printf("%X\n", ord(substr($newName, 5, 1)));