Tuesday, November 3, 2009

Problem with CSV file


Sometimes while CSV reports are created using people code, there will be a problem if there is comma in any of the fields. The second part of the field after the comma gets printed on the next column and the whole report will get messed up. While i had this problem i thought i need to write a separate code to handle this situation. Parsing through the field and get the comma, replace it by space and so on.

I didn't know that there was a delivered function Substitute to do this job for me.

Substitute (old_val, new_val)

The Substitute method replaces every occurrence of a value found in an array with a new value. To replace an element that occurs in a specific location in an array, use Replace.

If the array is one-dimensional, Substitute replaces every occurrence of the old_val in the array with new_val.

If the array is two-dimensional, Substitute replaces every sub array whose first element is equal to old_val, with the sub array given by new Val.

The following example changes the array &A to be ("John", "Jane", "Hamilton" ).

&A = CreateArray ();

&A[1] = "John";

&A[2] = "Jane";

&A[3] = "Henry";

&A. Substitute ("Henry", "Hamilton");

Nice function right?

0 comments:

Post a Comment

Total Pageviews

Copyright © Tech & Management Notes