Solved

string manipulation

Posted on 2001-07-27
2
146 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

13 Experts available now in Live!

Get 1:1 Help Now