String Comparison Operator
Xinok via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Apr 30 14:18:22 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list