Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string and make an array of integers in crystal report

I have a string with set of employee IDs separated by an _(Underscore). What i want to do is to split that into separate strings and convert them to integers and save them in an integer array. Is this possible in Crystal Reports? Is it possible to convert string into integer/number in Crystal Report?

I have tried using split function but still couldn't figure out how to use it to create an array.

I am very new to crystal report it would be a great help if you could help me out.

like image 306
direndd Avatar asked Nov 16 '12 05:11

direndd


People also ask

How do you split a string into an array of integers?

The string. split() method is used to split the string into various sub-strings. Then, those sub-strings are converted to an integer using the Integer. parseInt() method and store that value integer value to the Integer array.

How do I convert a string to a number in Crystal Reports?

Answer: Use the toNumber() function to convert a string field to a number. When using the toNumber function, test the value first with the isNumeric() function. isNumeric() returns a value of TRUE only if the value in the string can be correctly converted to a number.

Can you split a string array?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.


1 Answers

//create an array of strings by parsing a underscore-delimited string field
Stringvar Array strings := Split({table.string_field}, "_");

//empty numeric array; sized to match
Numbervar Array numbers;
Redim numbers[Ubound(strings)];

//populate array
Numbervar i;
for i := 1 to Ubound(strings) do (
  numbers[i] := ToNumber(strings[i])
);

//return
numbers;
like image 117
craig Avatar answered Oct 17 '22 08:10

craig