String Split

8 posts, 0 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 15 Mar 2013 Link to this post

    Hullo,

    I am basically using a wizard to generate report and pretty much of VS2k10's "built in" Designer so looks like this is the appropriate branch to post the report.

    I am trying to pick just the first name from the Northwind DB field and looks like split can do so. Well I am trying to use this in the expression editor :

    = IIf(IndexOfSubstr(Fields.ContactName, " ") > 0, Split(" ", Fields.ContactName), "False")

    Evidently, and that gives me "System.String[]"  but if I try expression as below :

    = IIf(IndexOfSubstr(Fields.ContactName, " ") > 0, Split(" ", Fields.ContactName)[0], "False")

    I get this message : An error has occurred while processing Report 'DemoReport2': Missing operator before '[0]' operand.

    Just to make my self clear I tried this and that works, may be I am missing something ?

    System.String[] s = new string[] { "telerik", "reporting" };
    Console.WriteLine(s[0]);

    Please comment ...

    This is the query I am using:

    SELECT
        Orders.CustomerID,
        Customers.ContactName,
        Orders.OrderDate,
        Orders.RequiredDate,
        Orders.ShippedDate,
        Orders.ShipVia,
        Orders.ShipCity
    FROM Customers INNER
    JOIN Orders ON
    Customers.CustomerID = Orders.CustomerID

    Thanks,
    -Aarsh
  2. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 15 Mar 2013 Link to this post

    Hello Aarsh,

    There is no expression iterator that can be used with a field returning a collection of objects, so instead of splitting the text, you can use the following expression to extract the first string before a space character:
    = IIf(IndexOfSubstr(Fields.FullName, " ") > 0, Substr(Fields.FullName,0,IndexOfSubstr(Fields.FullName, " ") ), "False")

    I hope this helps.

    All the best,
    Stef
    the Telerik team

    Telerik Reporting Q1 2013 available for download with impressive new visualizations. Download today from your account.

  3. DevCraft banner
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 15 Mar 2013 Link to this post

    Thank you Stef for your prompt response. The suggested solution most certainly should work but I need to access 2nd and 4th part of my portin, what I've posted is perhaps the for the demo application, and for ease of explaning my question. Stef, can you please point out some scenarios where one can actually use the split function ?

    If there aren't any, I would like to kindly request the demo so that I can actually add a small C# Class Library to have my userdefined function that I can use as black-box.

    Thanks,
    -Aarsh
  5. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 21 Mar 2013 Link to this post

    Hi Aarsh,

    In order to handle array values in an expression, our suggestion is to utilize an user function. Check out the following sample:

    public static string GetArrayItem(string[] values, int index)
    {
        return values[index];
    }

    Then you can use the following expression:
    = IIf(IndexOfSubstr(Fields.ContactName, " ") > 0, GetArrayItem(Split(" ", Fields.ContactName),0), "False")

    Generally handling arrays in expressions is in our TO DO list.

    Kind regards,
    Stef
    the Telerik team

    Telerik Reporting Q1 2013 available for download with impressive new visualizations. Download today from your account.

  6. Loren
    Loren avatar
    9 posts
    Member since:
    Dec 2013

    Posted 14 Sep Link to this post

    Has this been updated in the reporting system yet? Seems like it would be universally beneficial to have this built into the Telerik Reporting DLL

  7. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 15 Sep Link to this post

    Hi Loren,

    Getting an item at a given index from a collection is not supported via built-in expressions. You can create a custom function that returns the desired element. If you are using custom business objects, you can also extend them with functions performing the same logic - Work with raw data type's methods and properties.

    Please feel free to log a feature request in Telerik Reporting feedback portal. Features are considered for implementation based on the demand for them.

    Regards,
    Stef
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Loren
    Loren avatar
    9 posts
    Member since:
    Dec 2013

    Posted 15 Sep in reply to Stef Link to this post

    Hi Stef,

     

    Is there a way to have a user function return an object with properties rather than just a string? For example if i have a custom user function that calculates and parses a value i might want to return an object that has the following properties

    Object.FormattedValue

    Object.Error

    Object.ErrorMessage

    Object.SomeOtherProperty

     

    is this possible?

  9. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 17 Sep Link to this post

    Hello Loren,

    Yes, the user function can return a custom object which properties will be accessible. Yet custom object cannot be reused in one expression without calling again the user function.
    Instead you can use a data item like Table item and set its DataSource via binding to the result of the user function. Then the item will be able to display all properties of the data object.

    More examples can be found in How to use the ReportItem.DataObject property in expressions.

    Regards,
    Stef
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner