satoru

satoru

How to check if a Unicode codepoint represents a letter or an uppercase letter?

I’m working on the “Bob” exercise on the Elixir Track in Exercism.

I am testing for uppercase letter with this simple check: c in ?A..?Z, but one of the test cases requires that Unicode uppercase letters be handled.

I’ve Googled a little bit and couldn’t found anything useful. An answer on Stackoverflow suggested to use regular expression on the string. I wonder if there’s anything as simple as Unicode.is_upper? in the standard library.

Most Liked

malaire

malaire

Perhaps check if Unicode.category/1 returns :Lu.

EDIT: Just noticed that there is also Unicode.uppercase?/1 which does this exact check.

LostKobrakai

LostKobrakai

I was about to suggest ex_unicode as well, but given the nature of this being an exercise I doubt they expect people to use an external dependency.

egze

egze

Just a hint, I don’t think you need to check every codepoint individually, but instead try to work with the whole string input and just the String module.

malaire

malaire

Unicode is from ex_unicode package.

Alternatively if you want to stay with standard library, check out Regex character classes which include alpha and upper.

Dusty

Dusty

When I first solved Bob, I did so entirely with the Regex module. One of the comments my mentor made, was that, although Bob can be solved many ways, the intent of this exercise (on the Elixir track) is to get you familiar with the String module. I was encouraged to return to the String module, and solve the exercise without using any regexes at all. The solution I came up with turned out to be much more elegant than the regex solution, and indeed required only functions from String.

Here is a hint to get you started: Under what conditions would the uppercase version of a string be the same as the original? Are there other relationships like this you can leverage?

Where Next?

Popular in Chat/Questions Top

jace
I wanted to write a library for interacting with a Web API as a practical way of learning Elixir. However, there seem to be a lot of diff...
New
Iex.new
Hello!, I just started this week to discover Elixir. I’m a PHP-Programmer and did some sutff in Go too. The more I read about Elixir t...
New
stevensonmt
I’d like to provide my review of the Elixir Course module from Groxio. I have some criticisms but I’d like to start with the positives. ...
New
pietrofxq
I’ve bought the following books: Programming Elixir 1.6 Programming Phoenix 1.4 Programming Ecto Functional Web Development with Elixir...
New
OmanF
In the attached screenshot (taken from an exercise in “Programming Elixir”) can be shown that BugReport is defined as a struct that, itse...
New
boddhisattva
Greetings everyone, At my current workplace we're evaluating different ways of building a microservices architecture for some parts rel...
New
pdgonzalez872
Do we have a list of academic/research papers: about Elixir/Erlang? that use Elixir/Erlang? about the Beam? If so, could you please po...
New
Allyedge
So, I want to get an Elixir book, but don’t know which one to get. Both Programming Elixir 1.6 and Elixir in Action looks interesting, b...
New
younes-alouani
I'm studying Phoenix Framework but I want to understand basics first. Which book/mooc explains better the Design of Network-based Softwar...
New
Fl4m3Ph03n1x
Background I am trying to do the typical Ceaser cypher exercise in Elixir. The description of the exercise is as follows: Create an impl...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement