Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

substr
Hi All,

I need to copy a substring in a string which is completely out of the
primary string (in terms of the offset). substr does not allow me to do
so. Is there any other way in which I can do that ?

Thanks,
Manas.

Report this thread to moderator Post Follow-up to this message
Old Post
mk76@buffalo.edu
10-31-04 08:55 AM


Re: substr
mk76@buffalo.edu wrote:
> Hi All,

Hello,

> I need to copy a substring in a string which is completely out of the
> primary string (in terms of the offset). substr does not allow me to do
> so.

Do you mean like this:

$ perl -le' $_ = q/abc/; substr( $_, 20 ) = q/def/; print'
substr outside of string at -e line 1.


> Is there any other way in which I can do that ?

What do you want to use to fill in the string between the two?
If you want to do what I think you want to do then you could use pack:

$ perl -le' $_ = q/abc/; $_ = pack q/A20 A*/, $_, q/def/; print'
abc                 def

Or sprintf:

$ perl -le' $_ = q/abc/; $_ = sprintf q/%-20s%s/, $_, q/def/; print'
abc                 def



John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
10-31-04 08:55 AM


Re: substr
My earlier post was not quite clear. I will explain my problem in
detail here.

I have a string whose length is say 5. I need to copy another string
into this string but from an offset of 10.
I tried using substr but this is a limitation of substr and it gave me
a fatal error.
Is there any other function, method which will allow me to do so ?

Manas.


Quoting mk76@buffalo.edu:

> Hi All,
>
> I need to copy a substring in a string which is completely out of
> the
> primary string (in terms of the offset). substr does not allow me to
> do
> so. Is there any other way in which I can do that ?
>
> Thanks,
> Manas.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
mk76@buffalo.edu
10-31-04 08:55 AM


Re: substr
On Sat, 30 Oct 2004 22:46:39 -0400, mk76@buffalo.edu <mk76@buffalo.edu> wrote:
> My earlier post was not quite clear. I will explain my problem in
> detail here.
>
> I have a string whose length is say 5. I need to copy another string
> into this string but from an offset of 10.
> I tried using substr but this is a limitation of substr and it gave me
> a fatal error.
> Is there any other function, method which will allow me to do so ?
>
> Manas.


Yes, "rindex" is what (I think) you want; here is a small example of its use
:

my($newString)     =  substr($currentString, (rindex($currentString,
"searchString") + length("searchString".$replacementString)));


Although, John's reply to you first post was better.

--
WC -Sx- Jones
http://youve-reached-the.endoftheinternet.org/

Report this thread to moderator Post Follow-up to this message
Old Post
Chasecreek Systemhouse
10-31-04 08:55 AM


Re: substr
On Saturday, Oct 30, 2004, at 21:46 US/Central, mk76@buffalo.edu wrote:
> My earlier post was not quite clear. I will explain my problem in
> detail here.
>
> I have a string whose length is say 5. I need to copy another string
> into this string but from an offset of 10.
> I tried using substr but this is a limitation of substr and it gave me
> a fatal error.
> Is there any other function, method which will allow me to do so ?

Sounds like what you want to do is concatenate two strings with
something in between.  For example:

$ perl -e '
$foo="abcde";
$bar="fghij";
$foobar=$foo . "     " . $bar;
print "$foo : $bar : $foobar\n";
'
abcde : fghij : abcde     fghij

Is that close to what you are looking for?  If not, could you post some
sample code of what you are trying to do along with the error message,
sample input data, and the expected output data?  I find it easier to
debug buggy code than to debug descriptions of buggy code.

Regards,
- Robert


Report this thread to moderator Post Follow-up to this message
Old Post
Robert Citek
10-31-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:21 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.