Dart Runes join()
Syntax & Examples
Runes.join() method
The `join` method in Dart converts each element to a string and concatenates the strings using a specified separator.
Syntax of Runes.join()
The syntax of Runes.join() method is:
String join([String separator = "" ])
This join() method of Runes converts each element to a String and concatenates the strings.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
separator | optional | The string used to separate each element when concatenating. Defaults to an empty string if not provided. |
Return Type
Runes.join() returns value of type String
.
✐ Examples
1 Join characters with hyphen separator
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello'. - We use the
join
method with a hyphen separator to concatenate the characters into a single string. - We then print the joined string to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello');
String joinedString = runes.join('-');
print('Joined string: $joinedString');
}
Output
Joined string: 72-101-108-108-111
2 Join emojis with pipe separator
In this example,
- We create a sequence of Unicode code points
emojis
from the string '👋🏽🚀🌟'. - We use the
join
method with a pipe separator to concatenate the emojis into a single string. - We then print the joined string to standard output.
Dart Program
void main() {
Runes emojis = Runes('🚀🌟');
String joinedEmojiString = emojis.join(' | ');
print('Joined emoji string: $joinedEmojiString');
}
Output
Joined emoji string: 128640 | 127775
Summary
In this Dart tutorial, we learned about join() method of Runes: the syntax and few working examples with output and detailed explanation for each example.