473,769 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ 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 2670
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("'sdfsdfs d'","'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_a rray = 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','some thingelse for (123123,'someth ingelse. 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...@phpfreela ncer.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("'sdfsdfs d'","'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.n et

Apr 16 '07 #4

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

Similar topics

7
2613
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 children - when a child is fork()ed its pid is added to the linked list. I then have a SIGCHLD handler which is supposed to remove the pid from the list when a child exits. The problem I'm having is that very very occasionally and seemingly...
4
2547
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
15662
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 standard doesn't even care what a normal char is (because signed and unsigned have equal behavior). For example if someone does this: unsigned char a = -2; /* or = 254 */
11
18266
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 size of the collection" Not sure what is going on... any suggestions welcome! public static string fixStr(string aStr) { StringBuilder bStr = new StringBuilder(aStr.Length); for (int i = 0; i < aStr.Length; i++)
9
1631
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 some computers? I need to know as the program I've written relies on unsigned char to act as an 8-bit byte, and I need any unsigned char holding 255 to overflow to 0 when the ++ operator is applied.
8
8570
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? à è ì ò ù À È Ì Ò Ù á é í ó ú ý Á É Í Ó Ú Ý â ê î ô û Â Ê Î Ô Û ã ñ õ Ã Ñ Õ ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
1
4465
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 with my assignment. I hope you guys can point me in the right direction. I have a program which has an array of linked lists, with specific struct data elements inside each node of these lists. The linked lists are created dynamically and data...
7
2013
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 on the heap using malloc. This input is then run through a regex and another test. The result is passed back as a char pointer to the program for further processing The first time I call this function, it performs normally. However,
61
3284
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 and again. I know to remove code-duplication I have to make functions and pass arguments to them but I am not able to think of a way doing it. Can you post some example for me, out of this code:
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3958
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 we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.