473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Removing a backslash from a string

Hi, I want to know how to use split function to split the string based on backslash(\).
Actually backslash is appearing at the end of the string. and i want to remove it.
so if anyone could guide me as to what will be the syntax for removing backslash(\) from the string??
Mar 25 '07 #1
5 13778
miller
1,089 Expert 1GB
You could use a regex, substr, chop, many different techniques to remove a single defined character from the end of a string. It sounds like a regex might be the simpliest for your purposes, but I can't say for sure as you haven't told us much:

Expand|Select|Wrap|Line Numbers
  1. my $string = "test string\\";
  2. print "Before = '$string'\n";
  3. $string =~ s/\\$//;
  4. print "After = '$string'\n";
  5.  
- Miller
Mar 25 '07 #2
Thanks a lot, Miller.
I will try out on what you have guided me.

Actually, i am new to perl and right now i know very little abt perl So that's why i
may not have been able to communicate to you properly. But you have guessed it right.
But can u plz tell me that code snippet that you have written - is it for those two
(\) only becoz my string changes dynamically
that means it can have
my $string = "test string\\";
or this
my $string = "test string\\\";
or it can be this even
my $string = "test string\\\\";

That's why i was thinking of Split function. so that whereever it matches \ it stores the values in an array and i can mak use of only the desired 0th array
element.

Regards, Shalini
Mar 25 '07 #3
KevinADC
4,059 Expert 2GB
what you need to use is a quantifier

Expand|Select|Wrap|Line Numbers
  1. $string =~ s/\\+$//; 
Mar 25 '07 #4
miller
1,089 Expert 1GB
That's why i was thinking of Split function. so that whereever it matches \ it stores the values in an array and i can mak use of only the desired 0th array
element.
Hi Shalili,

I understand your approach, but it's not even close to the best method. One thing you'll learn pretty quickly about perl is that it is excellent at text processing. You can almost always accomplish something with a direct method instead of something indirect like using split. Split is used for just what it says, splitting a string into an array. Unless that's really what your ultimate goal is, you best bet is to stick with a regular expression.

Kevin's example spells out exactly what you'll need. Use it, and if you find the time, try to understand it as well. Start reading perldoc and the introductions to regular expressions. It's information that will serve you very well.

- Miller
Mar 26 '07 #5
Hi

Thanks for the help..
Yes,I have started reading perldoc..and its really informative.

-shalini
Mar 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: matt | last post by:
I have an upload script for a photo and a caption. It all goes pear shaped when I upload a character like ' " or / \ | Is there anyway I can parse through the filename when submitting the form and...
3
by: Terry Asher | last post by:
The following script does NOT escape the Apostrophe. Meaning when you mouseover the image the Alt tag says this: DMACC, It and then it stops. <SCRIPT Language="JavaScript"> var pos = "DMACC,...
3
by: lino | last post by:
Hello, I have the following string: const char plaintext = "Fourscore and seven years ago our \ fathers brought forth upon this continent \ a new nation, conceived in liberty, and dedicated...
6
by: John Salerno | last post by:
I have this: subdomain = raw_input('Enter subdomain name: ') path = r'C:\Documents and Settings\John Salerno\My Documents\My Webs\1and1\johnjsalerno.com\' + subdomain Obviously the single...
2
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
2
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I have a weird scenario where I'm trying to use a schema that was loaded into an XmlDocument. When I try to use that document later (myXDOC.OuterXml)... my text contains back slash values in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.