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

removing every even character from a string

Say I had .a.b.c and wanted to return abc. Any ideas as to how I'd do
this? Here's my attempt, but it doesn't work:

<?php
echo preg_replace('#(?:.(.))+#s', '$1', '.a.b.c');
?>

Any ideas?

Oct 9 '07 #1
3 4255
Yawnmoth,

Try focusing on the simple rules:

<?php

echo preg_replace('/[^A-Z]/i', NULL, '.a.b.c');

?>

Ouputs just what you need.

Best luck!

Vladimir
http://www.Vladimirated.com

Oct 9 '07 #2
"yawnmoth" <te*******@yahoo.comwrote in message
news:11**********************@50g2000hsm.googlegro ups.com...
Say I had .a.b.c and wanted to return abc. Any ideas as to how I'd do
this? Here's my attempt, but it doesn't work:

<?php
echo preg_replace('#(?:.(.))+#s', '$1', '.a.b.c');
?>

Any ideas?
Hi, If you know that the characters are dots, just str_replace them with
nothing

$new = str_replace('.','','.a.b.c');

or if they are every other character , regardless of value, try:

$string = '.d.fjdghdjtgkfdhfr';
$new = '';
for ($n = 2 to len($string)+1){
if ($n%2==0) $new .= substr($string,$n-2,1);
}

this will remove all the odd characters,
testing for $n modulus 2 ==1 will take out the even characters

HTH

Ron
Oct 9 '07 #3
On Oct 9, 4:14 am, "Ron Barnett" <N...@Spam.Thankswrote:
>
or if they are every other character , regardless of value, try:

$string = '.d.fjdghdjtgkfdhfr';
$new = '';
for ($n = 2 to len($string)+1){
if ($n%2==0) $new .= substr($string,$n-2,1);

}

this will remove all the odd characters,
testing for $n modulus 2 ==1 will take out the even characters

HTH

Ron
Or, even simpler:

$new = '';
for($i = 1; $i < len($string); $i += 2)
$new .= $string[$i];

Oct 9 '07 #4

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

Similar topics

5
by: Paradox | last post by:
In general I love Python for text manipulation but at our company we have the need to manipulate large text values stored in either a SQL Server database or text files. This data is stored in a...
4
by: Chad | last post by:
Hello, Im new to c++ and want to know how i can remove \n from a file. Im used to php where it is very easy to do. Im trying to remove the \n from a html file if that makes any difference. Thanks...
6
by: becte | last post by:
I am little bit confused Is this a legal way of removing a substring from a string? What about the second alternative using strcpy, is it ok even though the source and dest. strings overlap? ...
3
by: Nathan Sokalski | last post by:
I am having trouble removing cookies that I created with my site. Here is the code I am using to try and remove them: If Not Request.Cookies("username") Is Nothing Then...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
6
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii...
11
by: cmay | last post by:
I am having this problem... Lets say that your source XML is formatted like this: <somenode> Here is some text Here is some more text </somenode> When to a <xsl:value-of select="somenode" /I...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
3
by: MLH | last post by:
Back in mid-2003, lucason posted a question about removing punctuation chars from a string. Suggested code was posted using Replace function. Could the FN below be easily modified for use with A97...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
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
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,...
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,...

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.