- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

The Fortran standard `char (i [,kind] )` returns the character in position i in the processor collating sequence associated with the relevant kind parameter. The value of i must be in the range `0 < i < n - 1`, where n is the number of characters in the processor’s collating sequence. Is there a way to infer the value of `n` in a portable way within the programming environment?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@DataScientist wrote:What would `char(i)` behavior be if the collating sequence can be discontiguous?

Undefined.

I'll admit that I was not familiar with the behavior of MAXVAL/MINVAL when ARRAY is size zero. It would seem that:

ichar(minval(c))

where c is a zero-sized array of characters, does what you want.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Interesting question. I can't think of a reasonable way, offhand. What's your use case? I think some character sets have discontiguous ranges, which could complicate matters.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

The goal is to replicate `minval`/`maxval` and similar functionalities for scalar character sequences.

These two intrinsics return the maximum/minimum of the corresponding type and kind if the input array has zero size.

For characters, the result of the comparison is determined by the positions in the processor collating sequence.

Therefore, the last character in the collating sequence is required to fully mimic `minval`/`maxval` behavior.

What would `char(i)` behavior be if the collating sequence can be discontiguous?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@DataScientist wrote:What would `char(i)` behavior be if the collating sequence can be discontiguous?

Undefined.

I'll admit that I was not familiar with the behavior of MAXVAL/MINVAL when ARRAY is size zero. It would seem that:

ichar(minval(c))

where c is a zero-sized array of characters, does what you want.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I also have to admit that I did not know `minval` and `maxval` work with character arrays.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page