0

I have a strange scenario. I have a combo box that can have multiple selections. My data may contain commas. I'm using Infragistics controls so i'm not in control of the separator. Now, my combo box values are "A*A" "A%A" and "A,A". If the user selects all 3 values, the result looks like this:

    var arrValues = combo.igCombo('values'); //this retrieves the values            
    //arrValues contains this now: [A*A,A&A,A,A]

I'm parsing the values by a comma and you guessed it, i have an array of 4:

            array[0] = 'A*A'
             array[1] = 'A&A'
           array[2] = 'A' //the parse split "A,A" into 2 values
          array[3] = 'A'

array[2] should be

          array[2] = 'A,A'

and array[3] shouldn't exist. I have a function i thought would work but it doesn't.

      function getComboBoxValues(combo, delim, index) {
           var arrValues = combo.igCombo('values');
            var values = "";
           $.each(arrValues, function (i, o) {
               values += ((delim) ? o.split(delim)[index || 0] : o) + ',';
             }
           );
       return values;
    }

I call it like this:

  var array = getComboBoxValues($('#mycombobox'), ',', 0);

How can i parse my string:

[A*A,A&A,A,A]

into an array so it will have only 3 values

            array[0] = 'A*A'
             array[1] = 'A&A'
           array[2] = 'A,A'

Keep in mind, this may not be the order in which the string will be, so counting commas won't work.

My server side code is C#, so if this can be achieved in C#, please let me know. Thanks

7
  • Does the control not give you a way to get at the individual items in the combo box? Commented Mar 9, 2015 at 19:22
  • doesn't Java have a string.Split() method similar to in C#.NET this sounds so doable to me - tutorialspoint.com/java/java_string_split.htm Commented Mar 9, 2015 at 19:25
  • I'm not sure. I thought about that, after working with infragistics controls for the past 7 months, i don't recall anything Commented Mar 9, 2015 at 19:26
  • @MethodMan, i'm not using java Commented Mar 9, 2015 at 19:27
  • 3
    Use an encoded value "A%2CA" in combo-box, and decode it after split. Commented Mar 9, 2015 at 19:30

2 Answers 2

1

Looking at troycomptonenterprises.com and executing combo.igCombo('values'); gives you back an array containing the values (including the problem value) in a string. Nothing wrong here.

Output is:

 array[0] = "A*A"
 array[1] = "A&A"
 array[2] = "A,A"

Reading your question that is exactly what you want.

Sign up to request clarification or add additional context in comments.

6 Comments

let me implement your solution...give me a moment
@BoundForGlory If you need help, give me a comment.
go to troycomptonenterprises.com you will see exactly what i'm dealing with.
@BoundForGlory, looking at your website, it just gives my back an array with the values. Nothing wrong.
that example is using the latest infragistics code. i'm running a version thats over 18 months old. We'll be upgrading later this year. I hate 3rd party ui controls.
|
1

This javascript works:

var string = 'A*A,A&A,A,A';
var re = /([A-Z][\*&,][A-Z]),?/g;
var m;

do {
    m = re.exec(string);
    if (m) {
        console.log(m[1]);

        /*
        Outputs:
          A*A
          A&A
          A,A
        */

    }
} while (m);

3 Comments

this is working. I was thinking regex but i'm not the regex guru.
@BoundForGlory Nothing on the code, just formatted the code into the code block.
@BoundForGlory This solution fixes the symptom not the problem btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.