adaada2012spark-2014

Expression for finding an index in an array


How can I find the first character in a string that is the space character and return its index, with a single expression that can be used as part of Contract_Cases?

For example, if the string is:

Input : constant String := "abc def";

then the expression should return 4.


Solution

  • The question originally asked for the first non-blank character in the string, for which you need Ada.Strings.Fixed.Index_Non_Blank (ARM A.4.3(12) and (61)).

    As amended (the first blank character in the string), use Ada.Strings.Fixed.Index - see the OP’s comment below.