473,320 Members | 1,926 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,320 software developers and data experts.

Limit split to one single space...

109 100+
Hi.. i have a string that i would want split on a single blank space only.

eg.
$string = File: abc.txt

using split with white space i can get the name of the file : abc.txt

However i run into problem when there is many spaces in the filename.

eg.
$sting = File: a<5space>b<5 space>c.txt

using split on white space i will get: a b c.txt which contain one space in between only. However i would want to get the actually file name with the extra space. Any idea?
Jun 1 '07 #1
3 2153
I actually didn't understood what you are asking for.

But if your query i to get the file name "a b c.txt".

then the code is

perl -e '$string="File: a b c.txt"; ($filename) = $string=~m/.*?\s(.*)$/; print $filename;'
Jun 1 '07 #2
prn
254 Expert 100+
You can also limit the results of split to return a specific number of elements. See the split function

Best Regards,
Paul
Jun 1 '07 #3
miller
1,089 Expert 1GB
Hello Sky,

As Paul points out, the details of the split function allows for a limit of on the number of returned elements. This is definitely the way to go.

Expand|Select|Wrap|Line Numbers
  1. my $str = 'File: a   b   c.txt';
  2.  
  3. my $file = (split ' ', $str, 2)[1];
  4.  
  5. print $file;
  6.  
- Miller
Jun 1 '07 #4

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

Similar topics

4
by: Leandro | last post by:
There is an upper memory limit in Python? I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use 1.2G of memory, after this python crashes. Does someone know if python has...
2
by: mehul | last post by:
hi all, i am just starting with PERL and had this doubt related to the speical operator +. what it says is that in the line split( / +/,$line); it will not ignore the initial spaces as it starts...
3
by: Rich | last post by:
Hello all I have an application that is segmented into various Dlls, one of which contains caching mechanisms that create very large in-memory data structures. No matter what I do to attempt...
10
by: VM | last post by:
How can I limit the use of the PC's virtual memory? I'm running a process that basically takes a txt file and loads it to a datatable. The problem is that the file is over 400,000 lines long (77...
3
by: John Salerno | last post by:
This is an example in the book I'm reading: string fullName = " Edward C Koop "; fullName = fullName.Trim(); string names = fullName.Split(' '); string firstName = names; //...
7
by: Matthias Winterland | last post by:
Hi, I have a simple question. When I read in a string like: a='1,2,3,4,5 6 7,3,4', can I get the list l= with a single split-call? Thx, Matthias
6
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not...
4
by: Tem | last post by:
What would be the best way to split a string into a string array. with the following possible inputs? abc1 abc2 abc3 -single space abc1 abc2 abc3 -multiple spaces abc1,abc2,abc3 -comma...
8
by: Robert | last post by:
in regards to parsing directories.. Dim Sep(0) as char Sep(0) = "\" Dim Parts() as string = Filename.Split(Sep) What I want is to declare a temporary variable that is passed to split...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.