Do we have any functions in Ab Initio equivalent to INITCAP of oracle (to convert the first letter of each word to uppercase)? In oracle INITCAP works like: ex: INITCAP(the) ==> The ex:- INTICAP(The) ==> The I have looked into the below links, but did not get an answer. http://datawarehouse.ittoolbox.com/groups/technica l-functional/abinitio-l/initcap-1056911 Can anyone shed some light on this?

The element for loop allows a locally scoped variable to be declared. The code does not need to declare one separately. Improves logical isolation of variables.

$ m_eval “for (let s in string_split(‘now is dog in’, ’ ')) : string_length(s)”
[vector
3,
2,
0,
0,
3,
2]

Mind-blowing repliss.

Thank you very mach Shansara and Paul.

Hi Paul,
A slightly different approach would preserve the white spaces, carriage return, newline; inshort the original string.
out :: fn_1(in)=
begin
let int i;
let string(int)[int] vec=string_split(in, " ");
let string(int)[int] vec_jn;
vec_jn = for(i, i

Saravanan:

One thing I found on this detour was the “element for loop”. This seems a somewhat Pythonesque way to express the loop. I am not sure that this saves much execution time over simply creating a local variable from the subscripted element.

out :: string_titlecase5(in) =
begin
let int i;
let string(int)[int] vec = string_split_no_empty(in, " ");
let string(int) vec_jn = “”;
let string(int) w;

for (w in vec)
begin
vec_jn = string_concat(
vec_jn,
" ",
string_upcase(string_substring(w, 1, 1)),
string_downcase(string_substring(w, 2, string_length(w))));
end

out :: string_lrtrim(vec_jn);
end;

$ m_eval “string_titlecase5(’ all dog’)”
“All Dog”

Saravanan:

I agree that this is a much simpler, and surely faster, way to do titlecase.

However, I was also trying to preserve the whitespace that might be present in the original string. This would include blank, newline, carriage return, space, formfeed, horizontal tab, and vertical tab according to the [:space:] character class.

Is there a way to preserve the whitespace?

I sure do wish that it.toolbox.com would preserve the whitespace used for indentation of code.

Hi Paul,
An alternate way. Any suggestions are welcome.
out :: fn(in)=
begin
let int i;
let string(int)[int] vec=string_split_no_empty(in, " “);
let string(int) vec_jn=”";
for(i, i

Nice answers Paul giving you a thumps up

Fully agree with Paul and thanks for educating the stuff.

My requirement was backfill it worked with me.

Thanks,

Chetan

Agree with you Paul. The output for your test input data(" now is the time") should be “Now Is The Time”

I am trying to understand how Chetan Agarwal’s code will uppercase anything more than the first character of a string. What am I missing?

#!/bin/ksh
set -x
s=“‘now is the time’”
m_eval “string_concat(string_upcase(string_substring($s, 1, 1)), string_downcase(string_substring($s, 2, string_length($s) - 1)))”
s=“’ now is the time’”
m_eval “string_concat(string_upcase(string_substring($s, 1, 1)), string_downcase(string_substring($s, 2, string_length($s) - 1)))”

$ ./st.ksh

  • s=’ now is the time’
  • m_eval string_concat(string_upcase(string_substring(‘now is the time’, 1, 1)), string_downcase(string_substring(‘now is the time’, 2, string_length(‘now is the time’) - 1)))
    “Now is the time”
  • s=’ now is the time’
  • m_eval string_concat(string_upcase(string_substring(’ now is the time’, 1, 1)), string_downcase(string_substring(’ now is the time’, 2, string_length(’ now is the time’) - 1)))
    " now is the time"

Hi Chetan and pwatson,

First of all, many many thanks for your answers. In my recruitment both approaches worked out.

Thanks,
Chetan

I surely hope that there is some easier (faster) way to accomplish this. It would be much easier if all whitespace could be compressed into a single space. This function does not do that. Please, someone, make something better than I did.

out :: string_titlecase(s) =
begin
let dml_string_range_type r;
let int rl = allocate_with_defaults();
let int i = 0;
let string(1) so = reinterpret(s);

while (is_null(r) || (is_defined(r) && (length_of(r) > 0)))
begin
r = re_get_range_matches(s, ‘[[1]][[:word:]]*’, i);

if (length_of(r) > 0)
begin
i = r[0].index + r[0].length;
rl = vector_append(rl, r[0].index - 1);
end
end

for (i, i < length_of(rl))
begin
so[rl[i]] = string_upcase(so[rl[i]]);
end

out :: (string(‘’))eval([record so so], printf(‘reinterpret_as(string(%d), so)’, length_of(so)));
end;

$ m_eval “string_titlecase(‘all Dog is here 123’)”
“All Dog Is Here 123”


  1. :space: ↩︎

Hi Chetan,

I too agree with solution given by Chetan Agarwal.

Hi Chetan,

I was unable to find any command equivalent to the Oracle Initcap. But the following should do to achieve the same:

string_concat( string_upcase( string_substring( in.text, 1, 1)), string_downcase( string_substring( in.text, 2, string_length( in.text )-1 )) )

I don’t have Ab Initio access to check this right now. Please check it before using.

Thanks,
Chetan Agarwal