Strings

GetGoing: Introduction to Golang Data types and control structure
3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
This is a free item
$0.00
د.إ0.00
Kz0.00
ARS$0.00
A$0.00
৳0.00
Лв0.00
Bs0.00
B$0.00
P0.00
CA$0.00
CHF 0.00
CLP$0.00
CN¥0.00
COP$0.00
₡0.00
Kč0.00
DKK kr0.00
RD$0.00
DA0.00
E£0.00
ብር0.00
€0.00
FJ$0.00
£0.00
Q0.00
GY$0.00
HK$0.00
L0.00
Ft0.00
₪0.00
₹0.00
ISK kr0.00
¥0.00
KSh0.00
₩0.00
DH0.00
L0.00
ден0.00
MOP$0.00
MX$0.00
RM0.00
N$0.00
₦0.00
C$0.00
NOK kr0.00
रु0.00
NZ$0.00
S/0.00
K0.00
₱0.00
₨0.00
zł0.00
₲0.00
L0.00
QR0.00
SAR0.00
SEK kr0.00
S$0.00
฿0.00
₺0.00
$U0.00
R0.00
ZK0.00
Already have an account? Log In

Transcript

Hi, in this video, we're going to be talking about strings. So one thing to note is that all strings in golang are mutable, which means that you can change the value of strings again and again and again. So to define a string, you simply do our empty string. And you can do and what is equal to my name. It's as simple as that. For initialization and one line, you can also do this and one, colon equals to my name, and it's still gonna work.

So to check the mute to check the mutability of the string, I can simply do this, I can update it. So we got an error over here. That is because the colon equal to sign is only used for declaration. It's not useful assignment. For assignment we only have a single equal to, so once you've declared a variable, a memory is allocated for this variable. You don't need to Initial exit anymore, you can only change the value after that if you were able to update the variable.

So, with strings we have, we also have a lot of string functions. So let's say we got two variables called m m one and m two. And we can do, yeah. So, if you want to check em two contains Mo, no not. Let's see if we can do that. So you can include a strings.

Dork contains m one, m two. And it's gonna print out a boolean value true. That is because m two is contained in m one. This is a really useful function to find substrings in, in a larger string, and there are a lot of functions defined on a string. So you can do a string dot replace all so I can replace all of the M's in my M one Then, nope. Let's see what happens.

And I'm gonna go out and do crazy not using that anymore. Huh, look at this. So all of the M's were replaced by nodes by using the strings dot replace all. And there are different functions like we can split a string, according to its delimiters. And what's stripping essentially does is you specify a delimiter. And what happens is if you want to split a string by, let's say, space, so mining contains one space, so this is going to be one object, this is going to be a second object, and it's going to form an area of those.

So strings are split, we simply enter a string and we enter the delimiter. And it's going to return an array activists. So the string is Emma, the delimiter here is space. So let's see what happens. Added was returned. So in this video we learned a lot about strings, and how to function with strings how to concatenate strings with strings.

And concatenation is actually really simple. So, you simply do m one plus m two m one plus into that. And so any doubt with the strings function, you can, you can type just stripe strings, dot and you can read up the description of everything. And you can do a Ctrl spacebar, and then you can do enter to enter that function in this. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.