This is a migrated thread and some comments may be shown as answers.

String Split

7 Answers 1201 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 15 Mar 2013, 01:37 PM
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

7 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 15 Mar 2013, 05:32 PM
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.

0
Aarsh
Top achievements
Rank 1
answered on 16 Mar 2013, 01:19 AM
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
0
Stef
Telerik team
answered on 21 Mar 2013, 08:46 AM
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.

0
Loren
Top achievements
Rank 1
answered on 14 Sep 2016, 08:03 PM

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

0
Stef
Telerik team
answered on 15 Sep 2016, 11:25 AM
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
0
Loren
Top achievements
Rank 1
answered on 15 Sep 2016, 02:12 PM

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?

0
Stef
Telerik team
answered on 17 Sep 2016, 09:35 AM
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
Tags
Report Designer (standalone)
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Stef
Telerik team
Aarsh
Top achievements
Rank 1
Loren
Top achievements
Rank 1
Share this question
or