View Full Version : [Resolved] How to Trim Last item off Delimited String?
12-21-2005, 05:27 PM
I've got a delimited string and want to trim off the last item. The easiest way I can thing of doing this is to split the string then remove or erase the last item then rejoin the string
Any ideas on how to achieve this will be most welcome
12-21-2005, 05:37 PM
You could use a regExp to do that. Here are a couple of tutorials for explaing how to use regExp.
12-21-2005, 06:08 PM
var nStr = "a,ckd,ih,987,hghf,i,iu,8ujhd,0";
nStr = nStr.substring(0,nStr.lastIndexOf(","));
12-21-2005, 06:27 PM
// sOrig is now 'abc:def:ghi:jkl:mno:pqrs:tuv:wxyz:åäö'
// while sMod is 'abc:def:ghi:jkl:mno:pqrs:tuv:wxyz'
12-22-2005, 01:19 PM
Thanks a bunch for your replys, really appreciated.
I did manage to do it using the method I described in my first post but, your methods are a lot shorter and cleaner
The question now is which is the more efficient?
liorean's Regular Expression
Ancora's Substring and LastIndexof?
This what I had which is going to binned in favour of one of the above
var Temp = New Array();
12-22-2005, 10:43 PM
I would expect the two methods to be as efficient as one another since they are simply two ways of asking the browser to do the exact same thing. It depends on how the browsers implement the individual functions as to which will run faster on a given browser.
12-23-2005, 10:01 AM
Thanks for that.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.