Erlang: Get first n characters of a string

erlang string
erlang concat string
erlang reverse a string
erlang get first element of list
erlang lists
erlang empty string
erlang list index
lists sequence erlang

I have credit card number, let's say 5940043543536. And for security purposes I only want to display the first four digits.

How would one do that in erlang?

A string in Erlang is just a list of integers, so you can use lists:sublist/3:

1> String = "5940043543536".
"5940043543536"
2> lists:sublist(String, 1, 4).
"5940"

Note that the position argument starts from 1 and not 0.

Erlang -- string, take(String, Characters, Complement, Dir) -> {Leading, Trailing}. OTP 20.0 Returns the index of the first occurrence of Character in String. Returns 0 if  I have the following string: Getty <- "Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal." I want to display the first 10 characters. So I began by splitting the string into individual characters:

newer versions of Erlang have built in string functions. For your case

1> string:slice("123455678901234", 1, 4). 
"1234"

there is a string:substring function too, which works the same way, but it has been depreciated for slice.

string, Returns the index of the first/last occurrence of Character in String . 0 is returned if Character does not occur. str(String, SubString) -> Index rstr(String, SubString)​  In this article, we will discuss how to fetch/access the first N characters of a string in python. This N can be 1 or 3 etc. Python string is a sequence of characters and each character in it has an index number associated with it. For example, we have a string variable sample_str that contains a string i.e.

In case you are receiving binary (instead of string)

binary:part(<<"123455678901234">>, 1, 4).   
<<"2345">>

or if you need get last four digits

binary:part(<<"123455678901234">>, {byte_size(<<"123455678901234">>), -4}).
<<"1234">>

Erlang - Strings, Returns the index of the first/last occurrence of Character in String. 0 is returned if Character does not occur. str(String, SubString) -> Index rstr(String, SubString)  How can I get the first n characters of a string in PHP? What's the fastest way to trim a string to a specific number of characters, and append '' if needed?

Strings · Elixir School, Returns the index of the first occurrence of Character in String. of the maximum initial segment of String, which consists entirely of characters not from Chars. The first two (cut and head) are identical for a single-line string - they basically both just give you back the first two characters. They differ in that cut will give you the first two characters of each line and head will give you the first two characters of the entire input.

string(3erl) — erlang-manpages — Debian testing, text in quotations. Strings in Erlang need to be constructed using the double quotation marks. The method returns the index position of a character in a string. 5 When we run the above program, we will get the following result. "​hello.."  "Zips" three lists of equal length into one list of three-tuples, where the first element of each tuple is taken from the first list, the second element is taken from the corresponding element in the second list, and the third element is taken from the corresponding element in the third list.

String manipulation in Erlang., Strings, Char Lists, Graphemes and Codepoints. It first converts the string to lowercase and then uses String.graphemes/1 to get a list of the graphemes in the​  Extract first n characters from string. Select a blank cell, here I select the Cell G1, and type this formula =LEFT(E1,3) (E1 is the cell you want to extract the first 3 characters from), press Enter button, and drag fill handle to the range you want. Then you see the first 3 characters are extracted.

Comments
  • Thanks! My familiarity with this terminology is still weak. I appreciate your fast response.