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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you split a string into smaller parts?

Status
Not open for further replies.

msquires

Programmer
Aug 8, 2000
7
0
0
GB
Hi, I want to know how to split a string such as &quot;C:\my documents\mydoc.pdf&quot;. I want to split the string after the '.', so that I have two strings:<br><br>string 1 = C:\my documents\mydoc<br>string 2 = .pdf<br><br>Thanks..<br><br>Mike
 
Allright, we will try to consider the problem with different points of view. You can treat this problem in several ways.<br><br>------------------------------------------------------------<br><br>First of all, you probably want to&nbsp;&nbsp;get the extension, so you need the only 3 last characters of the string. This is a code to make it :<br><br>$string_1 = &quot;C:\my documents\mydoc.pdf&quot;;<br>$string_2 = ereg( &quot;\.???$&quot;, $string_1 );<br><br>That will result the following variable :<br>$string_2 == &quot;.pdf&quot;<br><br>Note : I am not sure of the regular expression used, so check it ! ;-)<br><br>------------------------------------------------------------<br><br>But you could choose to get all that is after the &quot;.&quot; by this way :<br><br>$string_1 = C:\my documents\mydoc.pdf;<br>$string_2 = explode( &quot;.&quot;, $string_1 );<br><br>Taht will result the following array :<br>$string_2[0] == &quot;C:\my documents\mydoc&quot;;<br>$string_2[1] == &quot;.pdf&quot;;<br><br>Note : as you can use the explode() function, you can use split().<br><br>------------------------------------------------------------<br> <p>Cédric CHERCHI<br><a href=mailto:pochacco@francemail.com>pochacco@francemail.com</a><br><a href= > </a><br>PHP/MySQL<br>
JavaScript<br>
Flash 4 scripting<br>
HTML/DHTML
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top