473,467 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how remove char around numbers

joe
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' 199 'something else'
any ideas on how to do this? thanks.

Apr 13 '07 #1
3 2655
On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
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' 199 'something else'
any ideas on how to do this? thanks.
Hm... use a regular expression, I'm thinking preg_replace ought to do
the trick...

Aerik

Apr 13 '07 #2
Aerik napisał(a):
On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
>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' 199 'something else'
any ideas on how to do this? thanks.

Hm... use a regular expression, I'm thinking preg_replace ought to do
the trick...

Aerik
<?php

$txt = array("'sdfsdfsd'","'as34444'","'234sdfd'","'2344' ");
foreach ($txt as $t) {
echo preg_replace("/^'([0-9]+)'$/","$1",$t)."\n";
}

$txt = "'sdfsdfsd' 'as34444' '12' '234sdfd' '2344'";
echo preg_replace("/'([0-9]+)'/","$1",$txt)."\n";

--
Wiktor Walc
http://phpfreelancer.net
Apr 13 '07 #3
joe
Thanks Iktorn

I ended up doing $where_clause_array = split(" ",$where_clause);
$where_clause = "";

foreach ($where_clause_array as $t) {
$where_clause = $where_clause . " " . preg_replace("/
^'([1-9]+)'$/","$1",$t);
}

I tried using echo preg_replace("/'([0-9]+)'/","$1",$txt)."\n"; but
It did not work. I got stuck with another preg_rplace trying to
replace ('123123','somethingelse for (123123,'somethingelse. If I
could make $sql = preg_replace("/'([0-9]+)'/","$1",$sql) work may be
that would take care of all instances of numbers surrounde by quotes.

On Apr 12, 11:12 pm, iktorn <s...@phpfreelancer.netwrote:
Aerik napisał(a):
On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
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' 199 'something else'
any ideas on how to do this? thanks.
Hm... use a regular expression, I'm thinking preg_replace ought to do
the trick...
Aerik

<?php

$txt = array("'sdfsdfsd'","'as34444'","'234sdfd'","'2344' ");
foreach ($txt as $t) {
echo preg_replace("/^'([0-9]+)'$/","$1",$t)."\n";

}

$txt = "'sdfsdfsd' 'as34444' '12' '234sdfd' '2344'";
echo preg_replace("/'([0-9]+)'/","$1",$txt)."\n";

--
Wiktor Walchttp://phpfreelancer.net

Apr 16 '07 #4

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

Similar topics

7
by: Kieran Simkin | last post by:
Hi all, I'm having some trouble with a linked list function and was wondering if anyone could shed any light on it. Basically I have a singly-linked list which stores pid numbers of a process's...
4
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
11
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the...
9
by: anongroupaccount | last post by:
I know that char will always be one byte, and that the size of a byte might not be 8-bits on some computers. Does that mean that an unsigned char might be able to hold numbers larger than 255 on...
8
by: Paul | last post by:
Hi, My VB is very rusty I'm afraid! What would be the most efficient way to remove the following ASCII characters from a string? à è ì ò ù À È Ì Ò Ù á é í ó ú ý Á É Í Ó Ú Ý â ê î ô û Â Ê Î Ô...
1
by: ziroi | last post by:
Hello! I am new here to the forums and still learning C. I understand your policies on coursework, but I have an error that I've run around and around and can't figure out where my problem is...
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
61
by: arnuld | last post by:
I have created a program which creates and renames files. I have described everything in comments. All I have is the cod-duplication. function like fopen, sprint and fwrite are being called again...
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
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.