English Uncategorized

C# is often used at work. Ranking 5 String methods that you should remember.

Foreword

Hello, I'm Kappa-chan.

In this article, I will write about the following topics.

Theme of this issue

5 String method rankings that you should remember

I'm going to explain the String methods in order that you should remember them.
KappaChan

The following articles are ranked 10th through 6th. Please take a look if you like.

CHECK

C#: Ranking of methods you should learn to use at work, String version: 6th to 10th

Foreword Hello, I'm Kappa-chan. I will be writing about the following topics. Theme of this issue St ...

続きを見る

Ranking announcement

KappaChan
The fifth most commonly used String method!

No5:Join

The fifth place is
Join method! This method is used for arrays rather than strings. It's quite useful to remember!

How to Use

It's like specifying an array as the second argument and a string to join the elements together as the first argument.

 result
dog and cat and mouse

This is very convenient because it allows you to use only one line for processing that would otherwise require multiple lines, such as repetitive statements.

KappaChan
The fourth most commonly used String method!

No4:Contains

In fourth place is the Contains method. This method is used to determine if a specified substring is included.

It is often used in Linq and other applications, so let's take this opportunity to learn it.

How to Use

Specify the string to search for as the first argument.

 result
true

False will be returned if you select a string that is not included.

KappaChan
The third most commonly used String method!

No3:Trim

The third place goes to the Trim method. It's kind of humble, but I use it really often! For some reason, it's quite common to have whitespace in a string!

How to Use

Just specify Trim with no arguments. That's easy.

 result
    kappachan
kappachan

It's hard to see in the result, but in fact, the spaces after the string are also gone.

You may want to erase only one of the front and back, so learn the following methods as well!

If you want to erase only the first half of the string, use TrimStart

If you want to erase only the second half of the string, use TrimEnd

KappaChan
The second most commonly used String method!

No2:Split

The second is the Split method, which is really common. The second is the Split method, which is really common and is often used in combination with foreach, so let's learn it together.

How to Use

This function creates an array with the string specified as the argument. It is very useful.

 result
dog
cat
mouse

You really use this a lot when you want to have multiple elements in a single item string. For example, if you have a string that looks like the following

targetCode = 1001|1002|1005

If you want to use each element, use targetCode
.Split(It's like splitting with '|'). This string concept is also used really often, so please learn it along with the Split method.

KappaChan
The first kappa!

No1:Replace

The first is the Replace method. I use it really often. I use it really, really often. It's intuitive and easy to understand, and it's my personal favorite method, with argument 1: the string before the change and argument 2: the string after the change.

How to Use

It is really easy to use. All you have to do is specify the string before the change as the first argument and the string after the change as the second argument.

 result
dog and cat
dog or cat

It's very simple. There are so many situations where you can use it, so you should definitely remember it.

Summary

This time, I explained the most commonly used methods in String, in a ranking format.

Programming schools and lectures don't really touch on how to use each method that much. What is a method? is the main point of explanation.

I would like to publish more articles like this one in the future.

Thank you for watching to the end.

-English, Uncategorized

X