CA Service Management

 View Only
  • 1.  How to use Split function in Spel Code

    Posted Oct 22, 2018 04:42 PM

    I have a string who I want to get separate (split) but I wish to use both sides of resultant string in different fields in Service Desk. Can u help me how to obtain this?


    For example:

    I have the original string variable as:

    twostrings = Consult ticket_ 02;

    string resume;

    //and the function split as: 

    split(resume, twostrings, "_");


    So the result it will be:

    resume = Consult ticket;


    But if I want to use the other part of the split result: 02, how I do it?


    Thanks for the help.



    Carlos Ramirez








  • 2.  Re: How to use Split function in Spel Code
    Best Answer

    Posted Oct 23, 2018 04:13 AM

    As far as I rememember split work differently in spel:

    the split function expect three arguments:

    1. a string array in which the splitted parts will be written.
    2. the string to split
    3. the needle, a search string where to split

    it returns the number of parts split was able to find.

    In your case it might look as


    int num_found;

    string twostrings;

    twostrings ="Consult ticket_ 02";

    string resume[2];

    num_found=split(resume, twostrings, "_");

    // num_found = 2
    // resume[0] will contain "Consult ticket"
    // resume[1] contains " 02"


    The only bad thing here: You need to know the expected maximum number of parts , before splitting. To be able, to declare the Array appropriately.



  • 3.  Re: How to use Split function in Spel Code

    Posted Oct 24, 2018 04:14 PM

    Thanks a lot for the response.

    It helped me to solve the problem I got in order to obtain the other side of the string with the split action.



    Carlos Ramirez