| | |
Perl: how to replace character '/' with '\'
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 40
Reputation:
Solved Threads: 6
0
#2 Oct 9th, 2009
perl Syntax (Toggle Plain Text)
#!/usr/bin/perl -w #ReplaceBackslashWithSlash.pl use strict; my $myPath = 'c:\perl\test'; # Example string containing backslashes print "\nOriginal string is: $myPath\n\n"; # The following command substitutes backslashes with forward slashes # You need to escape the backslash and slash with backslash $myPath =~ s/\\/\//g; print "Modified string is: $myPath\n";
•
•
Join Date: Sep 2009
Posts: 40
Reputation:
Solved Threads: 6
0
#4 Oct 10th, 2009
Sorry, I read your example wrong. This should do it. Too bad the substitute command uses slashes to delimit the two strings. It confuses me, but it should work this time.
perl Syntax (Toggle Plain Text)
#!/usr/bin/perl -w #ReplaceSlashWithBackslash.pl use strict; my $myPath = 'c:/perl/test'; # Example string containing backslashes print "\nOriginal string is: $myPath\n\n"; # The following command replaces forward slashes with backslashes # You need to escape the backslash and slash with backslashes $myPath =~ s/\//\\/g; #There must be a better way, but I don't know it. print "Modified string is: $myPath\n";
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 1
•
•
•
•
perl Syntax (Toggle Plain Text)
#!/usr/bin/perl -w #ReplaceBackslashWithSlash.pl use strict; my $myPath = 'c:\perl\test'; # Example string containing backslashes print "\nOriginal string is: $myPath\n\n"; # The following command substitutes backslashes with forward slashes # You need to escape the backslash and slash with backslash $myPath =~ s/\\/\//g; print "Modified string is: $myPath\n";
•
•
Join Date: Sep 2009
Posts: 40
Reputation:
Solved Threads: 6
0
#6 Oct 10th, 2009
Blank lines won't make any difference to how the program runs. Since I'm new to Perl I probably don't have a good sense of style yet. But I was trying to separate my code into three sections: introductory lines that appear in all programs, followed by setting up and printing the test string, followed by modifying and printing the resulting string.
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#8 Oct 28th, 2009
no i have no any idea about this. i am thankful to you for this topic. i like it very much.
![]() |
Similar Threads
- Replace character at a particular position (JavaScript / DHTML / AJAX)
- Search/Replace (MS SQL)
- Index of a character array (C++)
- Unicode - character printing probelm (Java)
- Replace Chars in String Problem (JavaScript / DHTML / AJAX)
- Howto | mssql seach and replace? (MS SQL)
Other Threads in the Perl Forum
- Previous Thread: Perl DBF file doubt
- Next Thread: Perl
| Thread Tools | Search this Thread |





