473,216 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,216 software developers and data experts.

finding and extracting from a string

Hello

Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn it
into array so that I can later operate on these strings.

And second, variation of it:
To get whole lines that contain some characters like 3 digits from a number
second b) :)
to extract only nmbers with some digits not whole lines.

Anyone ?
Please.

Jul 17 '05 #1
4 6911
On Sat, 11 Oct 2003 00:07:39 +0200, "lecichy" <co*****@vline.pl> wrote:
Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn it
into array so that I can later operate on these strings.
$array = explode(':', $line);

http://php.net/explode
And second, variation of it:
To get whole lines that contain some characters like 3 digits from a number
second b) :)
to extract only nmbers with some digits not whole lines.


Could you restate that more clearly; probably useful to show an example.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

Uzytkownik "Andy Hassall" <an**@andyh.co.uk> napisal w wiadomosci
news:oo********************************@4ax.com...
On Sat, 11 Oct 2003 00:07:39 +0200, "lecichy" <co*****@vline.pl> wrote:
Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn itinto array so that I can later operate on these strings.


$array = explode(':', $line);

http://php.net/explode
And second, variation of it:
To get whole lines that contain some characters like 3 digits from a numbersecond b) :)
to extract only nmbers with some digits not whole lines.


Could you restate that more clearly; probably useful to show an example.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


explode's fine but what if text pieces like name, number, in the line are
not separated by colons only but different chars like:

"name:address;number\otherinfo"

i I want to get a list of numbers only so the string from field between ";"
and "\" . Generally, we could say that the problem is abaut extracting a
string from between specified chars. Like finding sentences with exclamation
mark in some text ( so string from between chars "." and "!" )

About the second
we got lines like:

John:Anderson;6305912\single
Anna:Smith;6302678\married
Mark:Smith;6540945\married

and i want to print all lines with Smith. (I input Smith and get second and
third line printed ) so what I mean here is to print a line with exact
match.
Second, to print whole number filelds (only ) witch partial match. So
whole number that starts with some digits. In otherwords I put "630" in the
form and i want to get 6302678, 6305912 printed.

Gosh.. I mixed it up. I barely understand what I want so feel free to give
up on me :)
Jul 17 '05 #3
On Sat, 11 Oct 2003 01:37:43 +0200, "lecichy" <co*****@vline.pl> wrote:
Uzytkownik "Andy Hassall" <an**@andyh.co.uk> napisal w wiadomosci
news:oo********************************@4ax.com.. .
On Sat, 11 Oct 2003 00:07:39 +0200, "lecichy" <co*****@vline.pl> wrote:
Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn
it into array so that I can later operate on these strings.
$array = explode(':', $line);

http://php.net/explode


explode's fine but what if text pieces like name, number, in the line are
not separated by colons only but different chars like:

"name:address;number\otherinfo"

i I want to get a list of numbers only so the string from field between ";"
and "\" . Generally, we could say that the problem is abaut extracting a
string from between specified chars. Like finding sentences with exclamation
mark in some text ( so string from between chars "." and "!" )


Well, you've changed the problem now.

Looks like you're heading towards preg_split with a character class. But you
have to define what the separator characters are, of course.

$array = preg_split('/[:;\\]/', $line);
And second, variation of it:
To get whole lines that contain some characters like 3 digits from a
number second b) :)
to extract only nmbers with some digits not whole lines.


Could you restate that more clearly; probably useful to show an example.


About the second
we got lines like:

John:Anderson;6305912\single
Anna:Smith;6302678\married
Mark:Smith;6540945\married

and i want to print all lines with Smith. (I input Smith and get second and
third line printed ) so what I mean here is to print a line with exact
match.


preg_split as above, and then check for equality on the second element
returned ($array[1]).
Second, to print whole number filelds (only ) witch partial match. So
whole number that starts with some digits. In otherwords I put "630" in the
form and i want to get 6302678, 6305912 printed.
Partial leading match? Use substr to match the first n characters where n is
the length of your search string.
Gosh.. I mixed it up. I barely understand what I want so feel free to give
up on me :)


Hopefully the above gives you a nudge in the right direction at least.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #4
"lecichy" <co*****@vline.pl> wrote in message news:<bm**********@nemesis.news.tpi.pl>...
Hello

Heres the situation:
I got a file with lines like:

name:second_name:somenumber:otherinfo

etc with different values between colons ( just like passwd file)
What I want is to extract some part of it like all names or numbers from
each line, simply text fom between e.g. second and third colon. And turn it
into array so that I can later operate on these strings.

And second, variation of it:
To get whole lines that contain some characters like 3 digits from a number
second b) :)
to extract only nmbers with some digits not whole lines.

Anyone ?
Please.


http://in.php.net/preg_match
http://weitz.de/files/regex-coach.exe

---
"Silence is the only right answer for many wrong questions" --
G.K.Moopanaar, Indian Politician
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sammy | last post by:
Subject line says it all really. I have a 4 character long string, that contains a 32bit integer. Problem is i have no idea how i go about extracting it. Any help will be appreciated.
2
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
13
by: Randy | last post by:
Is there any way to do this? I've tried tellg() followed by seekg(), inserting the stream buffer to an ostringstream (ala os << is.rdbuf()), read(), and having no luck. The problem is, all of...
7
by: Tempo | last post by:
Hello. I am having a little trouble extracting text from a string. The string that I am dealing with is pasted below, and I want to extract the prices that are contained in the string below. Thanks...
5
by: tcwarrior | last post by:
Hi all. I am trying to write a little program where I extract some data out of a game in real time. The game writes some info to a log file, and I can access this in real time. The problem is that...
2
by: VictorTan | last post by:
Hello. I'm new to this forum. Hope that I don't make mistakes in here but if I do, please correct me if there is. Thanks. I also wanted to ask you guys regarding about the following following...
4
by: dexter48 | last post by:
Hi I'm searching for a string occurance in a text file. I find the string ok and write the results to a log file. But on the line above is also some information I need. How can i get that. The string...
5
by: Mukesh | last post by:
Hi, I am using framework 2.0. I am writing a foreach loop that will extract single dimensional arrays out of double dimensional array. I am trying writing something like this. string ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.