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

Sort a array of substring

Hi,
I need to order an array contains the strings order by
name server (iclsvi2 or iclsvi2 o iclsvi3)

service:ACS iclsvi2 started
service:ALM iclsvi2 started
service:BSOL iclsvi1 started
service:DBAPEX iclsvi1 started
service:DOCST iclsvi2 started

here the result I need

service:BSOL iclsvi1 started
service:DBAPEX iclsvi1 started
service:ACS iclsvi2 started
service:ALM iclsvi2 started
service:DOCST iclsvi2 started

Anyone can help me please?
Thx so mutch
Apr 4 '12 #1
17 2456
Rabbit
12,516 Expert Mod 8TB
Grab the first 7 characters after the first space. Then you can use that to sort.

The strpos() function will find the position of the first occurrence of a substring. Use that to find the space. The substr function will return a substring from a string. Use that to pull the 7 characters after the space. After that you can sort with whatever sort algorithm you want to use.
Apr 4 '12 #2
Thx Rabbit for the answear but I have these follow problem.

1) the log report I must order have different blank space between service:ACS and iclsvi2
2) I have a lot of name server iclsvi2, iclsvi1 but also webse02 or otrweb3 and so on

I would know how extrac name server of these different string to order.
In the Unix sheel there is a command to select a portion of string at coloumn 2 rather than column 1 or coloumn 3.
I don't know if is possible with PHP language.

Anyone can help me please?
Thx so mutch
Apr 6 '12 #3
Rabbit
12,516 Expert Mod 8TB
You really have to mention that kind of stuff at the very beginning. How do you expect to get the right answer if you give us non-representative data?

Please post a new sample dataset containing the different variations contained in your data. Only then can we work towards a correct solution.
Apr 6 '12 #4
There are a lot of log files from server.
They rappresent the status of cluster.
The log files are send in a directory and I must open order and pubblic on web.
The log files are all similar (ALIAS DB follow by CLUSTER NAME follow by STATUS) like the example I post.
I can't extract the string CLUSTER NAME because how I try to explain it's change for every log files and I can't permit to analyze all kind of logs files because are thousend!
I know only the structure of the log files.
Each rows have
ALIAS NAME [number of irregular blank space] CLUSTER NAME [number of irregular blank space] STATUS

Hope now my problem is more clear
Apr 10 '12 #5
Rabbit
12,516 Expert Mod 8TB
So the number of spaces around the cluster name is unknown. But it looks like there's no spaces before or after the entire row. Use a regular expression to find the portion of the string that is bound by a space on each end. That will be your cluster name.
Apr 10 '12 #6
Do you know what expression can I use to find portion of the string that is bound by a space on each end ? thx
Apr 11 '12 #7
Rabbit
12,516 Expert Mod 8TB
This expression would do it.
Expand|Select|Wrap|Line Numbers
  1. \s(\w+)\s
Apr 11 '12 #8
Sorry is a PHP expression???
what mean \s(\w+)\s?
Apr 12 '12 #9
Rabbit
12,516 Expert Mod 8TB
It's the regular expression I mentioned in the previous post.
Apr 12 '12 #10
is not clear.
Hope to find one solution on this form.
wrong idea
Apr 13 '12 #11
Rabbit
12,516 Expert Mod 8TB
It's not clear because you don't know what regular expressions are. You should look up the documentation in php on it.
Apr 13 '12 #12
Thanks Rabbit for your suggest.
Strange I don't thought about...
I'm not a PHP developer and I have few time to resolve these problem so I sign here to these form for a quick response from PHP developer.
If your solution is study the documentation on PHP... thank you...you solution is \s(\w+)\s ???? you think is clear for a not PHP developer?
In other response about these argument anyones post ad example or try to be clear most possibleand you say me to study the documentation?
for me was more help if you give me ad example of function to order an array or to help me to find another solution....
Apr 17 '12 #13
Rabbit
12,516 Expert Mod 8TB
I don't give out code unless the requestor has shown a willingness to learn what's required. If you're working in PHP, but don't know PHP, I expect you to learn it. I'm not here to spoon feed you answers.
Apr 17 '12 #14
anddddd is with an example you can explain, teacher ! example not solution teacher, you know the different?
Apr 18 '12 #15
instead of the traditional from left to right character analysis..

make it from right to left??..

-because all these strings ended at the word "started"??..

ahaha.. im confused..ahaha.. :))
Apr 18 '12 #16
\s(\w+)\s

looks familiar to me..

it is like a scape in C.
like \n \t \a..
ang maybe \s for space, \w+ for characters or word.
i'll try to use this expression..
thanks rabbit! :))
Apr 18 '12 #17
Rabbit
12,516 Expert Mod 8TB
This returns the string two into the variable $matches.
Expand|Select|Wrap|Line Numbers
  1. preg_match("/\s(\w+)\s/", "one       two three", $matches);
Apr 19 '12 #18

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

Similar topics

2
by: Boefje | last post by:
Hi, What I want is simple, but I can't figure it out at the moment. Let's say this is an array names $matches: Array ( => Array (
19
by: David | last post by:
Hi all, A while back I asked how to sort an array of strings which would have numerals and I wanted to put them in sequential numerical order. For example: myArray = "file1"; myArray =...
6
by: Tamir Khason | last post by:
Let's say I have Point and I want to sort it circle way (e.g. 2;2.4;1,8;2,8,5;4;8,2;7,1;4 The algo for this is: if ((p.X<p.X & p.Y<Avg(p).Y & p.Y<Avg(p).Y) | (p.X>p.X & p.Y>Avg(p).Y &...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
4
by: christiang | last post by:
Hi guys I'd like to sort a multidimensional array that hasn't numerical index, in fact it is like: Array ( => Array ( => mobile => 1 )
1
by: millw0rm | last post by:
i got 2 array one holds the actual data n another is user generated sort order... how to sort array #1 according to array #2???? array shld be sorted according to sortorder Array #1 ( =Array...
4
by: Santosh Nayak | last post by:
Hi, Is it possible to sort the array of struct based on the data members. e.g. struct { int a ; float b ; char c ; } TEMP ;
5
by: tienlx | last post by:
Hi all, I want to sort an array of struct _line: .... typedef struct _line { int x1; int x2; } line;
4
by: Kovu | last post by:
Hi, I have the next problem. I want to sort the array for the key, using a function. I have been looking for a function to operate with arrays, but I haven't found anything. Ej: Array ( ...
7
by: JWest46088 | last post by:
I am trying to write a program based off of a flowchart. The program is supposed to sort an array. I am having trouble getting it to sort though. I know it has something to do with my code, but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.