codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  ridding of beginning/ending spacebars in each element of a list.  hermanningjaldsson at 10:24 on Wednesday, September 24, 2008
 

i have an array.

each element in this array is a string.

sometimes there are elements in this array which contain, say, the value "-\s\s\s\s".

in such instances i want to rid of those spacebars.
i dont want to rid of any other spacebars though.

so basically, i want to rid of all spacebars at the beginning and
at the end of each element in the list.


how do i do that?



  Re: ridding of beginning/ending spacebars in each element of a list.  S_Flex at 13:24 on Thursday, September 25, 2008
 

you could do this.

my @stuff = ("- ", " -");

for (my $i = 0; $i <= $#stuff; $i++) {

print $stuff[$i], "1\n";
$stuff[$i] =~ s/(\A\s+|\s+\z)//g; # remover
print $stuff[$i], "2\n";

}

hope it helps


  Re: ridding of beginning/ending spacebars in each element of a list.  S_Flex at 14:01 on Thursday, September 25, 2008
 

you may want to use this regex.

$stuff[$i] =~ s/(?:\A\s+|\s+\z)//g;

Because the (?:pattern) does not capture characters like () does and you don't want to capture characters if you don't need to.
Which will make things a little faster overall.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: ridding of beginning/ending spacebars in each element of a list.
•  Excel to XML
•  DHTML tutorials?
•  The Ballarat Airline Company (BAC)
•  Re: Problem to declare global variable in Object oriented perl
•  Issue with Javascript between web servers
•  Not Allowing Copying from Site
•  Re: dereferenceing a string to a constant name
•  Scrolling Javascript Product Slider


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008