The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
Hopefully a quick question..... :nervous:
What's the easiest way of getting a section of a string based upon an X specified delimiter? To show what I'm after, let's say that I have two strings that always contain the same number of delimters such as "X_Y_Z" and "A_B_C_D". The length of each of the parts might change (eg: "AAA_BB_C_DDDDD") but the number of delimeters don't. Now if a string is concatenated at the end of it such as "X_Y_Z_123" then I want to get "_123" including the underscore. If the string is "A_B_C_D_123_456" then I want to get "_123_456" out of it. If the string is "X_Y_Z" then I want a blank value. In the first string I would want to get from the 4th part onward and in the second string I want to get from the 5th part onward. Any thoughts? I know that I could turn the string into an array based upon the delimiter and then just say get from the X value onward if X isn't blank but then I'd have to concatenate all of the array values after X back together again. Hopefully I'm just thinking about it too much and that there's a quick way of getting the results. ![]() Thanks, |
#2
|
|||
|
|||
![]()
Easiest would probably be to split the string into it's parts, then rejoin them when you got what you want
PHP Code:
hope this gets you on your way, Modin |
#3
|
||||
|
||||
![]() Quote:
Thanks! Kevin |
#4
|
|||
|
|||
![]() Quote:
preg's are fast and this would avoid a new array being created and the loop. But for that to work you'd need to know what characters could come between the delimiters. |
#5
|
||||
|
||||
![]() Quote:
I hadn't thought of using a preg. I may have to do the array trick though because the values may be anything. What I'm working on is I did a small hack job to the BV Shoutbox Full code so that I could easily implement it in vBa CMPS but my changes were quick & dirty. I'm thinking that I can simplify the process so that instead of releasing a modified version of the PHP file I can instead write up instructions for the users to follow and modify the file themselves; that way the only thing I'd have to supply are the instructions and the new templates to create. It's not high on my priority list right now but I figured I'd still put it out there in case anybody else wants it. ![]() Thanks, Kevin |
#6
|
|||
|
|||
![]()
yeah, I thought about preg as well...though I find that when you have a common delimiter explode is much easier.
And technically a new array is created when you use preg, the matches it returns are in an array. And you don't know how it's implemented in the back end, so it's very possible that many arrays are created ![]() |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|