Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to add a space after first word ina s entence

Reply
Thread Tools

how to add a space after first word ina s entence

 
 
sudip05@mailcity.com
Guest
Posts: n/a
 
      07-18-2006
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

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      07-18-2006
wrote:

> 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.

 
Reply With Quote
 
 
 
 
sudip05@mailcity.com
Guest
Posts: n/a
 
      07-18-2006
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


Brian McCauley wrote:
> wrote:
>
> > 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Finding a sentence (more than one word & punctuation (, . ;)) ina string? Kev Jackson Ruby 12 01-12-2006 05:43 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57