how to add a space after first word ina s entence

S

sudip05

Hi All,
I am having a senmtence. After the first word, I have to add a
single space there...can anybody gimme a coincise code. I tried
breaking up the sentence, but it removes the spaces also which I dont
want.

Code snippet
first line: selects lineString example: "int *ptr ptr is a pointer"

if($lineString =~ m/(\s*\@param\s*)\*(.*\r*\n*)/)
{
$lineString = $1.$2; /*$1 is "int " $2 is "ptr is a pointer"
*/

I have to produce output like "int ptr(then 1 single space) is a
pointer". So I have to manipulate $2 in such a way that after first
word in $2, there goes another extra space.



Can anybody help.

Thanks,

sudip
 
B

Brian McCauley

I am having a senmtence. After the first word, I have to add a
single space there...can anybody gimme a coincise code.

s/(\w+)/$1 /;

Somehow, I suspect that's not what you meant.
first line: selects lineString example: "int *ptr ptr is a pointer"

if($lineString =~ m/(\s*\@param\s*)\*(.*\r*\n*)/)
{
$lineString = $1.$2; /*$1 is "int " $2 is "ptr is a pointer"
*/

That is not valid Perl - it will not compile.

There was no '@params' in your example input so your pattern will not
match.

That yo you think the pattern /(.*\r*\n*)/ matches?
I have to produce output like "int ptr(then 1 single space) is a
pointer". So I have to manipulate $2 in such a way that after first
word in $2, there goes another extra space.

The dolar-digit variables are readonly. You need to copy the string to
an ordinary scalar variable then manipulate it in the usual way. (e.g.
with s///).

Please produce minimal but complete code to illustrate your quesrtion.
Can anybody help.

Only if you describe what you want to achive in term that other people
could possibly understant.
 
S

sudip05

Hi Brian,
I am sorry..yes, u r very true...the code that I gave wont
work, but you gave the corect solution(inserting a space after the
first word in a sntence)...thanks a lot..... :)

~Ciao
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top