Home: Perl Programming Help: Advanced:
Help In Cutting A String....



yotam_k
Deleted

Jan 12, 2001, 3:46 AM


Views: 3723
Help In Cutting A String....

Lets Say i have a text , article , that I load it from a file ,
the text contains Plain text .
I need to cutt each line in the text after 40 Charcters in the line and then transfer it to the next line and then cut The next line by the same messurments (after 40 Char.) [ all this content should be of course , in a Integral (with $ sign...) ] .
I need this for adding this text into a thin table space .

I know that there is a Cammand in perl that does it Which I think it beeing called SUBSTRING but i realy dont know it's syntex and that whay I'm Asking .

If I didn't simplfy my question :
" Could someone tell me the syntex SUBSTRING to cut the first 40 Charcters From the Integral "$string" ?




thank you all !!!!!!!!




randor
User

Jan 12, 2001, 8:46 AM


Views: 3720
Re: Help In Cutting A String....

Yotem_k,

the syntax for the substring is as follows:

$var= substr("$string", starting position, length of cutout);

so from what i am gathering you would need something like this:
$var= substr("$string", 40); #if you leave the last number off it will by default return all from that point on.
print "$var\n";

i hope this clears it up for you.

Randor



yotam_k
Deleted

Jan 13, 2001, 5:29 AM


Views: 3710
Re: Help In Cutting A String....

Thank You Very Much Randor , It Helped Very Much !
Thank You !




yotam_k
Deleted

Jan 13, 2001, 5:35 AM


Views: 3710
Re: Help In Cutting A String....

But I have one more question to deep my knowlge :
you said that :

$var= substr("$string", starting position, length of cutout);

so if i want to cutt from the 28 char. I should write :
$var= substr("$string", 28 , 40);

?
And thank you again.
Yotam.




randor
User

Jan 13, 2001, 6:20 AM


Views: 3709
Re: Help In Cutting A String....

$var= substr("$string", 28 , 40);

that will cut from the 28th character to the 40th, if you want to cut everything from the 28th on use this:
$var= substr("$string", 28);

glad i could help:)



japhy
Enthusiast / Moderator

Jan 13, 2001, 7:58 AM


Views: 3708
Re: Help In Cutting A String....

No, it does not cut from the 28th to the 40th. You were right when you said the third argument is the length of the substr. It cuts from the 28th to the 67th, which is 40 characters.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


randor
User

Jan 13, 2001, 9:53 AM


Views: 3707
Re: Help In Cutting A String....

yeap, my bad..

i rushed and did not think about what i was saying.. i appologize, and thank you for showing me the error of my ways.