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

prepend operator?

Hello -

Is there an operator where I can prepend a string to a string, without
repeating the variable name? I'm aware of the concatenation operator,
where you can do

$string .= $ending;

but I would like to do

$start = "mis";
$middle = "apprehend";
$end = "ing";

echo $string =. $start;

"misapprehend"

$string .= $end
echo $string =. $start

"misapprehending"

?
Jun 27 '08 #1
5 4813
On Wed, 18 Jun 2008 20:25:37 +0200, <la*****@gmail.comwrote:
Is there an operator where I can prepend a string to a string, without
repeating the variable name?
No easy one, any possibility will likely be more typing then less typing,
and that's the only thing to gain from it.
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #2
la*****@gmail.com wrote:
Hello -

Is there an operator where I can prepend a string to a string, without
repeating the variable name? I'm aware of the concatenation operator,
where you can do

$string .= $ending;

but I would like to do

$start = "mis";
$middle = "apprehend";
$end = "ing";

echo $string =. $start;

"misapprehend"

$string .= $end
echo $string =. $start

"misapprehending"

?
I assume, based upon the rest of your post, that you meant $string
rather than $middle. So, with that in mind, what is wrong with:

$string = $start . $string . $end;

?

Jun 27 '08 #3
sheldonlg wrote:
>
I assume, based upon the rest of your post, that you meant $string
rather than $middle. So, with that in mind, what is wrong with:

$string = $start . $string . $end;

?
The question was: "Is there an operator where I can prepend a string to a
string, without repeating the variable name?"

Read the question carefully, then look at your answer, then see if you can
see what is wrong with it!


Jun 27 '08 #4
Paul Lautman wrote:
sheldonlg wrote:
>I assume, based upon the rest of your post, that you meant $string
rather than $middle. So, with that in mind, what is wrong with:

$string = $start . $string . $end;

?
The question was: "Is there an operator where I can prepend a string to a
string, without repeating the variable name?"

Read the question carefully, then look at your answer, then see if you can
see what is wrong with it!
I saw that, and my "what uis wrong with" was not meant as an answer but,
rather, I was saying "What's the big deal? It is just so simple to use
this". (Speech inflexion doesn't present itself well on the internet).

Anyway, just for the sake of argument suppose that there were such an
operator and it was =. Then to do the job you would need to say:

$string .= $end;
$string =. $start;

It seems to me that this is more complicated and more typing and more
error-prone than what I presented.
Jun 27 '08 #5
sheldonlg wrote:
Paul Lautman wrote:
>sheldonlg wrote:
>>I assume, based upon the rest of your post, that you meant $string
rather than $middle. So, with that in mind, what is wrong with:

$string = $start . $string . $end;

?
The question was: "Is there an operator where I can prepend a string
to a string, without repeating the variable name?"

Read the question carefully, then look at your answer, then see if you
can see what is wrong with it!

I saw that, and my "what uis wrong with" was not meant as an answer but,
rather, I was saying "What's the big deal? It is just so simple to use
this". (Speech inflexion doesn't present itself well on the internet).
Since the OP is gone, and I certainly don't know if meant "prepend"
instead of "append".

But lets say he did.

Why not unshift it on an array, then join the array with ''? Or reverse
sort later?

Jeff
>
Anyway, just for the sake of argument suppose that there were such an
operator and it was =. Then to do the job you would need to say:

$string .= $end;
$string =. $start;

It seems to me that this is more complicated and more typing and more
error-prone than what I presented.
Jun 27 '08 #6

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

Similar topics

6
by: flamesrock | last post by:
so I know you can append a string. But how do you *prepend* a string, as shown in the following code #dirList = #string = """position""" #for x in len(dirList): # string += '>>...
37
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend...
5
by: lazypig06 | last post by:
Hi ! I'd like to ask everyone this question. I am currently maintain a website which have hundreds of pages and lot of subdirectories. Most of these pages contains a common function (let's call...
1
by: y0sh1 | last post by:
I'm new at using macros in excel and need to prepend zeros to a column of data. i know i'll need an if statement with some kind of loop. the logic goes something like, select cell, if number is...
6
by: Geoff Berrow | last post by:
I have a record in a MySql database which can be edited. Each time it is edited I want to give the user the opportunity to summarise the changes, which I store in a field. It doesn't really...
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: 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:
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
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: 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
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,...
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...

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.