Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does Perl have a '.Indexof' for counting characters in a string?

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
If I used JavaScript I would know how to count characters in a string, but in Perl I'm not fimilar on how to accomplish this.<br><br><br>Can Perl do something similar to this?<br><br><b>--if ($company.index == 22)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$company-&gt;write('\r');</b><br><br>What I want to do is take the string value of $company and once the string contains 22 characters add a carriage return.<br> <p>Dano<br><a href=mailto:dskryzer@hotmail.com>dskryzer@hotmail.com</a><br><a href= > </a><br>What's your major malfunction
 
Try this:<br><FONT FACE=monospace><br>if ( length($company) == 22 ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;# Add a carriage return to the end of $company.<br>&nbsp;&nbsp;&nbsp;&nbsp;$company .= &quot;\n&quot;;<br>}<br></font><br><br><FONT FACE=monospace>length</font> returns the length of the named string.&nbsp;&nbsp;The &quot;.=&quot; bit is like saying '$company = $company . &quot;\n&quot;'.&nbsp;&nbsp;ie, use perls concatenation operator to add the string on the right to the end of the string on the left.<br><br>Hope this helps.<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top