Here's a nifty regex that will split, and do word wrap on a string.

$string =~ s/\G(.{1,37})(?<=\S)\s+/$1\n/gm;

->  -----Original Message-----
->  From: Kristofer Wolff [mailto:[EMAIL PROTECTED]]
->  Sent: Wednesday, October 10, 2001 4:29 AM
->  To: perllist
->  Subject: String spliiting problem
->  
->  
->  hi all,
->  
->  i am searching for a possibility to split a sting by words 
->  if its longer
->  than n Charakters.
->  I know there is a regexp for splitting words, bu i don't 
->  know how to use it
->  in this example. Maybe you can help me ?
->  If a string is longer than 37 Charakters, slpit bevor the 
->  last word with
->  adding an \n.
->  
->  I've got:
->  
->  $string = shift;
->  $st_l = length($string);
->  if($st_l > 37)
->  {
->      [... do somthing with $string ..]
->  }
->  return($string);
->  
->  I am thinking of splitting the strings in Words_array : if 
->  this \w or \W ?
->  an can i use
->  @words = split(/\w/, $string); ???
->  
->  and put them togeteh  while counting the charakters ??
->  
->  put if there an better way ???
->  
->  
->  thanxs for help kris
->  
->  _______________________________________________
->  Perl-Win32-Web mailing list
->  [EMAIL PROTECTED]
->  http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
->  

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to