473,402 Members | 2,050 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,402 software developers and data experts.

How to seperate Model Numbers from a string

rahulephp
Can anyone please let me know how to separate Model Numbers from a string

For Ex Titles:
1) Sony DCSW380B 14MP Camera
2) Casio 10MP Camera EX-Z3/3
3) Panasonic Lumix Camera DMC-G1 12MP

Output would be:
For 1) "DCSW380B 14MP" OR ""DCSW380B"
For 2) "10MP EX-Z3/3" OR "EX-Z3/3"
For 3) "DMC-G1 12MP" OR "DMC-G1"

Criteria:
1) All letters of model number are CAPITAL
2) It may include alphabets, numbers or special symbol like "/", "-"
3) Model numbers can be anywhere in the title (not a specific position like 2nd in array on explode)

Not sure if i need to use preg_match function.

Please assist. Thanks in advance
Jun 23 '10 #1
2 1262
JKing
1,206 Expert 1GB
If the products are consistent you could build a list of keywords to be removed. For example you have list that includes sony, panasonic, casio, camera etc. Then run your strings through a function to remove any keywords.

Just a thought though... there maybe a more elegant solution out there.
Jun 23 '10 #2
I got the solutions in another way,
Here it is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $titles = Array('Sony DCSW380B 14MP Camera', 'Casio 10MP Camera EX-Z3/3', 'Panasonic Lumix Camera DMC-G1 12MP');
  3.  
  4. foreach($titles as $item)
  5. {
  6.     if(preg_match_all('/\b([A-Z0-9\/\-\+]+)\b/', $item, $tmp))
  7.         print implode('||', $tmp[1]).'<br />';
  8. }
  9.  
  10. ?>
  11.  
The output is separated by "||" in case if i need it in future.
Jun 24 '10 #3

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

Similar topics

4
by: Sugapablo | last post by:
I have column data that looks like this: id | ColumnA ---+----------- 1 | 12,35,123 2 | 1,23 3 | 233,34,35 4 | 34 And I want to be able to make a WHERE clause where I can match up a
2
by: Eric Lilja | last post by:
Hello, I'm working on my C++ homework and I have a question about the following function. It's part of my code the handles command line arguments. Here's the code: static void...
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
6
by: Matthias S. | last post by:
Hi, I'm pretty sure this is as easy as it gets, but I couldn't find anything in the documentation. I'd like to change the string representation of an int so that the numbers get padded with...
3
by: chris | last post by:
Hi there, I have a string containing of a letter and numbers, i.e. "B1234". How can I saperate the numbers and the letter in two seperate strings? string1 = B string2 = 1234 I also have...
2
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection...
23
by: mrvendetta1 | last post by:
#include <stdio.h> #include <string.h> #include <stdlib.h> #define N 33 void StringToIntArray(const char *s1); void takeinteger(int i); int main() { char string; printf("enter a string of...
9
by: Michael D. Ober | last post by:
OK, I can't figure out a way to optimize the following VB 2005 code using StringBuilders: Public Const RecSize as Integer = 105 Private buffer As String Public Sub New() init End Sub...
3
by: thanawala27 | last post by:
hi I dont know how to seperate a string containing commas. suppose i have a string $text = "this, is, fine"; i want to seperate the above string into this is fine
1
by: ehcy | last post by:
i want to seperate the numbers i will input in textbox to declare it each number but i don't know how.. plz help me.. example.. i will input.. 5 3 6 4 8 9 and i will declare each number...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.