473,558 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing a backslash from a string

10 New Member
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 13832
miller
1,089 Recognized Expert Top Contributor
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
shalini jain
10 New Member
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 Recognized Expert Specialist
what you need to use is a quantifier

Expand|Select|Wrap|Line Numbers
  1. $string =~ s/\\+$//; 
Mar 25 '07 #4
miller
1,089 Recognized Expert Top Contributor
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
shalini jain
10 New Member
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
15864
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 remove any illegal characters like this??? Thanks in advance Matt
3
22222
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, It\'s the Smart Thing to Do."; document.write("<img name=img5 id=img5 src='/homepage/dmaccstudent" + Math.floor(Math.random() *20) + ".jpg'...
3
2817
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 \ to the proposition that all men are created equal.";
6
3181
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 backslash at the end of 'path' will cause a problem, and escaping it with a backslash seems to fix this problem, but how does escaping work when I...
2
3236
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 of the file name. I suppose the options are: 1. Part of the path string, ie all returned path strings should have a trailing backslash. 2. Part...
3
22960
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) replaced, but the second is not ??? Is it in general better to use double backslash in filepaths ? thanks, Stef Mientki
2
2154
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 are left with a single backslash.
11
3040
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 spaces, but not in the inner string(\"and a inner string\\\"). Will anyone please tell me how to do this?
8
4038
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 front of every quotation mark and I can't seem to get rid of them. myXDOC.OuterXml.Replace("\\","") doesn't work. myXDOC.OuterXml.Replace(@"\","")...
0
7836
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8061
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5455
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3603
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1165
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
872
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.