Reputation: 11
I would like to know how to check if the first character of string is a uppercase in prolog .
Upvotes: 1
Views: 475
Reputation: 60034
code_type/2
, char_type/2
are your friends:
?- String='Hello world',get_string_code(1,String,First),code_type(First,upper).
String = 'Hello world',
First = 72.
?- String="Hello world",get_string_code(1,String,First),code_type(First,upper).
String = "Hello world",
First = 72.
?- String=`Hello world`,get_string_code(1,String,First),code_type(First,upper).
String = [72, 101, 108, 108, 111, 32, 119, 111, 114|...],
First = 72.
These 3 examples show different kinds of strings, and be aware last one is available only starting from SWI-Prolog v.7, where it replaces double quoted literals, that were, historically, lists of codes.
Upvotes: 2