Previous Thread
Next Thread
Print Thread
Rate Thread
#103284 11/16/2001 3:44 AM
Joined: Dec 2000
Posts: 595
Member
Member
Offline
Joined: Dec 2000
Posts: 595
hi

i believe theres a pattern-something command to do this, as theres no function to truncate a string based on its length (at least i couldnt find one...). so, huh... do you know how to make this?

thanks.

Sponsored Links
#103285 11/16/2001 5:01 AM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
If I understand you correctly, substr will do that: http://perldoc.com/perl5.6.1/pod/func/substr.html

[ 11-16-2001: Message edited by: Dave_L ]

#103286 11/16/2001 5:53 AM
Joined: Dec 2000
Posts: 595
Member
Member
Offline
Joined: Dec 2000
Posts: 595
$name = substr($name, 0, 100);

what if the $name variable doesnt have a hundred characters? will it return the same string, or will it return an error?

thanks.

#103287 11/16/2001 5:13 PM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
I don't know offhand. If the documentation doesn't cover that case, try it and see what happens. wink

If it doesn't work the way you want, you could check the length of the string first:

Code
code:

[ 11-16-2001: Message edited by: Dave_L ]

#103288 11/16/2001 8:45 PM
Joined: Dec 2000
Posts: 595
Member
Member
Offline
Joined: Dec 2000
Posts: 595
thanks alot.

Sponsored Links
#103289 11/17/2001 7:08 AM
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
P.I.T.A. / Programmer
Offline
Joined: Sep 2000
Posts: 755
Quote
quote:
What happenes why you try it???

The best way to learn is to try things first, then ask if you don't understand what happened smile


"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
#103290 11/18/2001 8:59 PM
Joined: Dec 2000
Posts: 595
Member
Member
Offline
Joined: Dec 2000
Posts: 595
i dont know how to handle perl errors...

it would be something like this, i presume

$name = substr($name, 0, 100) or die "$!";

where the variable $! has the error message, or the error code, or 1/0 for error... O_o or even return the error for the $name variable, where one could print $name to see whats inside...


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
hatter
hatter
USA
Posts: 69
Joined: January 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240506)