digitalmars.D.learn - String Comparison Operator

• Jolly James (1/1) Apr 30 2017 Is there a String Comparison Operator in D?
• =?UTF-8?B?54Sh?= (2/3) Apr 30 2017 ~
• Xinok (6/7) Apr 30 2017 Yeah, just the usual comparison operators:
• bauss (11/18) Apr 30 2017 Just to clarify.
• ag0aep6g (15/24) Apr 30 2017 [...]
• Xinok (7/30) Apr 30 2017 Regarding concatenation vs appending, it's kind of both depending
• tcak (4/5) Apr 30 2017 You normally use double equation marks (==) to do that.
Jolly James <j.j jmail.com> writes:
```Is there a String Comparison Operator in D?
```
Apr 30 2017
=?UTF-8?B?54Sh?= <mu mu.co.jp> writes:
```On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:
Is there a String Comparison Operator in D?

~
```
Apr 30 2017
Xinok <xinok live.com> writes:
```On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:
Is there a String Comparison Operator in D?

Yeah, just the usual comparison operators:

"abc" == "abc"
"abc" != "ABC"

~ is for string concatenation, i.e.:

"abc" ~ "def" == "abcdef"
```
Apr 30 2017
bauss <jj_1337 live.dk> writes:
```On Sunday, 30 April 2017 at 16:15:41 UTC, Xinok wrote:
On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:
Is there a String Comparison Operator in D?

Yeah, just the usual comparison operators:

"abc" == "abc"
"abc" != "ABC"

~ is for string concatenation, i.e.:

"abc" ~ "def" == "abcdef"

Just to clarify.

It's not actually a string concatenation operator, it's an array
appending operator.

Strings are just an alias for immutable(char)[] and not actually
a type unlike other languages like C#, Java etc. where strings
are objects.

In fact it doesn't have any operators that doesn't work with any
other type of arrays. Just like functions such as replace etc.
aren't necessarily string functions, but works with any type of
arrays.
```
Apr 30 2017
ag0aep6g <anonymous example.com> writes:
```On 04/30/2017 09:05 PM, bauss wrote:
On Sunday, 30 April 2017 at 16:15:41 UTC, Xinok wrote:

[...]
~ is for string concatenation, i.e.:

[...]
It's not actually a string concatenation operator, it's an array
appending operator.

Appending is related but distinct. `~` does concatenation. `~=` does
appending.

https://dlang.org/spec/arrays.html#array-concatenation

Strings are just an alias for immutable(char)[] and not actually a type
unlike other languages like C#, Java etc. where strings are objects.

I get what you mean, but while we're splitting hairs: `string`
definitely is a type. It's the same type as `immutable(char)[]`.

In fact it doesn't have any operators that doesn't work with any other
type of arrays. Just like functions such as replace etc. aren't
necessarily string functions, but works with any type of arrays.

Not an operator, but `foreach` has special support for transcoding
between the different UTF variants.

Regarding functions, narrow strings (`string`, `wstring`) are special
cased all over phobos. It's because as ranges they have dchar elements,
but as arrays they have char/wchar elements. std.array.replace [1] also
mentions strings in its signature because of this.

[1] https://dlang.org/phobos/std_array.html#.replace
```
Apr 30 2017
Xinok <xinok live.com> writes:
```On Sunday, 30 April 2017 at 19:05:18 UTC, bauss wrote:
On Sunday, 30 April 2017 at 16:15:41 UTC, Xinok wrote:
On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:
Is there a String Comparison Operator in D?

Yeah, just the usual comparison operators:

"abc" == "abc"
"abc" != "ABC"

~ is for string concatenation, i.e.:

"abc" ~ "def" == "abcdef"

Just to clarify.

It's not actually a string concatenation operator, it's an
array appending operator.

Strings are just an alias for immutable(char)[] and not
actually a type unlike other languages like C#, Java etc. where
strings are objects.

In fact it doesn't have any operators that doesn't work with
any other type of arrays. Just like functions such as replace
etc. aren't necessarily string functions, but works with any
type of arrays.

Regarding concatenation vs appending, it's kind of both depending
on the type of the operands. What I mean is all of the following
are valid:

[10, 20] ~ [30, 40] == [10, 20, 30, 40]  // Concatenation
[10, 20] ~ 30       == [10, 20, 30]      // Appending
10 ~ [20, 30]       == [10, 20, 30]      // Prepending
```
Apr 30 2017
tcak <6uqekg+anzstagnqueug sharklasers.com> writes:
```On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote:
Is there a String Comparison Operator in D?

You normally use double equation marks (==) to do that.

auto name = "Jack";
if( name == "Jack" ) writeln("Hi Jack!");
```
Apr 30 2017