I need help grabbing some string operation in Javascript. I have a sample string as
var str = 'Supplier^supp^left^string*Spend (USD MM)^spend^right^number^5';
The string is basically a configuration for a portlet for two columns as Supplier and Spend..I have to get the column names from this string. Each star follows a new column config. In this case there are configs for only 2 columns and hence only 1 star exists in my string. Supposedly if there are 2 columns the string will look like
var str = 'Supplier (Name)^Supplier^left^string*Spend (USD MM)^Spend^right^number^5*Location (Area)^Loc^right^string^*Category ^Categ^right^string';
So from the above string i had written a logic to get the desired string as after the 2nd caret i want 'Supplier'(1stcolumn data name and not 'Supplier (Name) which is a display name) ,(Moving to 2nd column after the star)after the 2nd caret 'Spend'.Similarly 'Loc' (3rd column) and 'Categ' (4th column). Can anybody help me achieve this? Here is what i had written
function getColNamesfromConfig(str) {
var i = str.indexOf('^');
var tmpCatStr = str.slice(i + 1);
var catField = tmpCatStr.slice(0, tmpCatStr.indexOf('^'));
var j = tmpCatStr.indexOf('*');
var tmpStr = tmpCatStr.slice((j + 1));
var k = tmpStr.slice(tmpStr.indexOf('^') + 1);
var valField = k.slice(0, k.indexOf('^'));
return { categoryField: catField, valueField: valField };
}