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

Remove numbers from words and work with the numbers

142 100+
Hi.

Say I have the following id. webandwe13

Is there I way I can remove the 13 to work with it and add it back when I'm done.

I have a profile program and when the user upload I want to increase the number but don't know how to remove the number to work with it.

Is it even possible?

Thanks

Webandwe
Nov 17 '08 #1
4 1348
Dormilich
8,658 Expert Mod 8TB
there are various ways. you can for instance use a Regular Expression to remove and get number as well as cutting it off with string functions (if there are length constraints on either the number or the letter part).

adding the number is easy:
[PHP]$your_string = $letter_part . $number;[/PHP]

regards
Nov 17 '08 #2
Markus
6,050 Expert 4TB
Why not do yourself a favour and store the number in a database. Takes away the hassle of regular expressions *shiver*.
Nov 17 '08 #3
Using the basic's of PHP and some string functions, we can do this (I am not sure, this is the best efficent way) This would work fine with integers.
If the number involves decimals don't use this script it would not work consistently (e.g 1.1 would work but 0.1 will not)
If you understand the snippet, you will understand why?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $str = 'webandwe13';
  3.     $number = strrev(strrev($str) + 0); //extracting the number
  4.     $new_number = $number + 1; // increment the number by one
  5.     $str = str_replace($number, $new_number, $str); // replacing  with the old number
  6.     echo $str;
  7. ?>
Output: webandwe14
Nov 18 '08 #4
r035198x
13,262 8TB
Why not do yourself a favour and store the number in a database. Takes away the hassle of regular expressions *shiver*.
That is the approach I would use. See this thread for a similar discussion.
Nov 18 '08 #5

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

Similar topics

8
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
18
by: prasanna.hariharan | last post by:
Hi guys, I want to remove certain words from a c++ string. The list of words are in a file with each word in a new line. I tried using the std::transform, but it dint work. Anybody got a clue...
11
by: steve smith | last post by:
Hi I'm still having some problems getting my head round this language. A couple of things don't seem to work for me. First I am trying to obtan a count of the number of words in a sting, so am...
10
by: brainy_muppet | last post by:
Basically, I have a code with is almost finished but I've having difficultly with the last stage of the process. I have a program that gets assigns different words with a different value via...
3
by: Danny Yeadon | last post by:
Hi I need to remove unwanted characters from phone numbers from my phone bill to analyse the data. Some examples are 02 48222222 i need to remove the space +61266667656 ...
16
by: Markus Dehmann | last post by:
According to several C++ tutorials, calling srand like this to initialize the random number generator seems to be standard: srand((unsigned)time(0)); But it leads to the same random number...
3
by: joe | last post by:
hello I have a string that has values in quotes 'hello' 'here' '199' 'something else' I need to remove the quotes only when they are around numbers. To make the string lookg like 'hello' 'here'...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
3
by: Bouzy | last post by:
I have a list of words and am trying to replace all the numbers in my list with whitespace. for word in words: numbers = re.search('+', word) word = clearup(word) if word in...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.