473,657 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;

"misapprehe nd"

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

"misapprehendin g"

?
Jun 27 '08 #1
5 4828
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.c om 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;

"misapprehe nd"

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

"misapprehendin g"

?
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
26502
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 += '>> %s'%dirList.pop() #(????????????) # to return
37
5053
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 timestamps on each line. I would like for this to work for all the printf-line functions (fprintf, etc...) as well as C++ I/O streams (cout and cerr). The key here is that I would like to get these timestamps on the lines of text written to...
5
3396
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 it "foo()" on top of each of these pages. I've tried to use auto prepend and .htaccess to prepend a file which contains an exact function foo() that is being used on other pages. I kept getting error "Cannot redeclare foo() in..." when I try to...
1
4185
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 less than 9 digits long prepend "0" until it is equal to 9 digits. if equal to 9 digits do nothing and select next. can anyone give me some idea as to how the syntax would look like? any help is much appreciated.
6
1542
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 warrant another table it would be sufficient to prepend the data to the existing data in the field. Sorry if this is really a MySql problem, but at the moment I can only think of a php/html hidden field solution. -- Geoff Berrow (put thecat out...
0
8407
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
8319
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
8837
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...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
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
4171
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...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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
1732
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.