Solved

string manipulation

Posted on 2001-07-27
2
157 Views
Last Modified: 2010-03-05
hello experts!
how do i insert a '<br>' every 24th character in a string?
0
Comment
Question by:nikitin
2 Comments
 

Expert Comment

by:cidaris
ID: 6327958
Hopefully, this does what you're looking for.  Obviously, just replace the example string.  Also, I don't know if you want to insert before/after/replace the 24th character, but only slight modifications would be needed.

Thanks
cidaris

$oldstring = "1234567890123456789012345678901234567890123456789012345678901234567890";

my @newstring = split(//,$oldstring,-1);
print "@newstring\n";
print "$newstring[5]\n";
print "$newstring[24]\n";

for (my $intX = 0; $newstring[$intX] ne ""; $intX++){
   if (($intX != 0) && ($intX % 24 == 0)){
      # character is not 0 and is a multiple of 24
      $char = "\<br\>" . "$newstring[$intX]";
   }
   else {
      $char = "$newstring[$intX]";
   }
$out_string = $out_string . $char;
}

print "$out_string\n";


0
 
LVL 8

Accepted Solution

by:
bebonham earned 100 total points
ID: 6327959
$str=~s/(.{23})/\1<BR>/g;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now