Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
input string is:

A,01/01/1900,12/30/9999, 2AB9500,A9,8999,BNVV

I want to get the 4th element and remove the space for that field and join it back to the string.

What I have tried:

I tried :

@capture = $string =~ /([^,]+)/g; # capture all the fields with spaces
$capture[pos] =~ s/^\s+|\s+$//g;
$string = join '',@capture;
Posted
Updated 21-Dec-17 13:06pm

1 solution

If all your requirement is to remove the space then

$string =~ s/\s//g; 

should be fine

if you only want to filter the index-4 item leave other as it is then try the following example
PERL
$line="A,01/01/1900,12/30/9999, 2AB9500,A9,8999,BNVV";
@arr=split /\//, $line; 
$arr[4] =~ s/\s//g; 
$line=join "/", @arr; 
print $line."\n";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900