English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang 문자열

문자열 텍스트를 쌍속호호를 사용하여 Erlang에서 문자열 텍스트를 구성할 수 있습니다. Erlang에서 문자열을 구성하려면 쌍속호호를 사용해야 합니다. 예를 들어 “Hello World”.

이어rlang에서 문자열을 사용하는 예제-

예제

-module(helloworld). 
-export([start/0]). 
start() ->
   Str1 = "This is a string", 
   io:fwrite("~p~n",[Str1

The above example creates a named Str1 string variables. The string "This is a string" has been assigned to the variable and displayed accordingly.

The output of the above program will be:

"This is a string"

Next, we will discuss variousOperations available for Strings. Please note that for string operations, you also need to include the string library.

Serial NumberString Methods and Descriptions
1

len

This method returns the length of a specific string.

2

equal

This method returns a boolean value to determine whether one string is equal to another string.

3

concat

This method merges2Concatenates a string and returns the concatenated string.

4

chr

This method returns the index position of the character in the string.

5

str

This method returns the index position of the substring in the string.

6

substr

This method returns a substring of the original string based on the starting position and the number of characters from the starting position.

7

left

This method returns a substring of the original string based on the starting position and the number of characters from the starting position.

-module(helloworld). 
-import(string,[left/3 
-export([start/0]). 
start() -> 
   Str1 = "hello", 
   Str2 = left(Str1,10,$.), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

"hello....."

right

This method returns a substring from the right side of the string based on the number of characters.

语法

right(str1,number)

参数

  • str1 −This is the string from which the substring needs to be extracted.

  • Number −This is the number of characters that need to appear in the substring.

返回值

It returns a substring of the original string based on the right side of the string and the number.

-module(helloworld). 
-import(string,[right/2 
-export([start/0]). 
start() -> 
   Str1 = "hello World" 
   Str2 = right(Str1,2), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

"ld"

right with trailing character

This method returns a substring from the right side of the string based on the number of characters. However, if the number is greater than the length of the string, you can choose to include the trailing character.

语法

right(str1,number,$character)

参数

  • str1 −This is the string from which the substring needs to be extracted.

  • Number −This is the number of characters that need to appear in the substring.

  • $Character −The character at the end of the string is included.

返回值

It returns a substring from the original string based on the right side of the string and the number.

-module(helloworld). 
-import(string,[right/3 
-export([start/0]). 
start() -> 
   Str1 = "hello", 
   Str2 = right(Str1,10,$.), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

".....hello"

to_lower

This method returns the string in lowercase form.

语法

to_lower(str1)

参数

  • str1 −이는 소문자로 변환해야 하는 문자열입니다。

返回值

lowercase string is returned.

-module(helloworld). 
-import(string,[to_lower/1 
-export([start/0]). 
start() -> 
   Str1 = "HELLO WORLD", 
   Str2 = to_lower(Str1), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

"hello world"

to_upper

이 메서드는 대문자 형식으로 문자열을 반환합니다。

语法

to_upper(str1)

参数

  • str1 −이는 대문자로 변환해야 하는 문자열입니다。

  • Return Value −返回大写字符串。

-module(helloworld). 
-import(string,[to_upper/1 
-export([start/0]). 
start() -> 
   Str1 = "hello world", 
   Str2 = to_upper(Str1), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

"HELLO WORLD"

sub_string

返回String的子字符串,从子位置Start到字符串的末尾,或者到Stop位置(包括Stop位置)。

语法

sub_string(str1,start,stop)

参数

  • str1 −这是需要从其返回子字符串的字符串。

  • start −这是子字符串的开始位置

  • stop −这是子字符串的停止位置

返回值

返回String的子字符串,从子位置Start到字符串的末尾,或者到Stop位置(包括Stop位置)。

-module(helloworld). 
-import(string,[sub_string/3 
-export([start/0]). 
start() -> 
   Str1 = "hello world", 
   Str2 = sub_string(Str1,1,5), 
   io:fwrite("~p~n",[Str2

위의 프로그램을 실행하면 다음과 같은 결과를 얻게 됩니다.

"hello"