Scala Converting Each Array Element to String and Splitting -
i have array loaded in, , been playing around in repl can't seem work.
my array looks this:
record_id|string|false|1| offer_id|decimal|false|1|1,1 decision_id|decimal|false|1|1,1 offer_type_cd|integer|false|1|1,1 promo_id|decimal|false|1|1,1 pymt_method_type_cd|decimal|false|1|1,1 cs_result_id|decimal|false|1|1,1 cs_result_usage_type_cd|decimal|false|1|1,1 rate_index_type_cd|decimal|false|1|1,1 sub_product_id|decimal|false|1|1,1 campaign_id|decimal|false|1|1,1
when run command:
for(i <- 0 until schema.length){ val convert = schema(i).tostring; convert.split('|').drop(2); println(convert); }
it won't drop anything. not splitting on |
strings immutable, , split
, drop
don't mutate string - return new one.
you need capture result in new val
val split = convert.split('|').drop(2); println(split.mkstring(" "));
Comments
Post a Comment