WEBVTT 00:00:07.260 --> 00:00:15.030 It this video we're going to learn some functions and methods we can use to manipulate strings. 00:00:15.210 --> 00:00:18.380 OK so first of all this creates a string variable. 00:00:18.720 --> 00:00:20.950 I've called it's message. 00:00:21.960 --> 00:00:23.440 So we're going to send it to 00:00:26.790 --> 00:00:41.020 welcome to my web sites of a good time exploring my web site. 00:00:41.040 --> 00:00:43.310 All right. 00:00:43.530 --> 00:00:51.640 OK so first we want to get the lens of our string. 00:00:51.860 --> 00:00:52.450 OK. 00:00:52.620 --> 00:00:53.580 So we're going to echo 00:00:56.190 --> 00:01:01.310 lines of my message. 00:01:02.740 --> 00:01:05.280 OK. 00:01:06.330 --> 00:01:11.030 And we're going to use we can concatenate the string with another drink. 00:01:11.060 --> 00:01:16.220 I'm going to use a function string length. 00:01:16.890 --> 00:01:23.160 So if you want to explore the function just to control K and you can see that it will get the string 00:01:23.190 --> 00:01:23.870 length. 00:01:24.210 --> 00:01:25.750 OK. 00:01:27.120 --> 00:01:36.030 All right so the promiser are going to give it is going to be a string message. 00:01:36.340 --> 00:01:43.900 Now if you save and refresh we can see that the length of our message is 61 characters. 00:01:44.890 --> 00:01:45.840 OK. 00:01:46.200 --> 00:01:52.410 All right so now let's have a late break. 00:01:55.910 --> 00:01:57.550 OK. 00:01:58.950 --> 00:02:04.270 Now we want to count the number of words inside our string. 00:02:04.590 --> 00:02:16.890 So we're going to echo my message contains and we're going to add a string and this time we're going 00:02:16.890 --> 00:02:26.160 to use the function string word counts as t r underscore where it counts. 00:02:26.430 --> 00:02:30.450 OK let's give it the barometer. 00:02:31.080 --> 00:02:34.050 The message variable at the end. 00:02:34.050 --> 00:02:41.700 Let's add another string weights. 00:02:43.040 --> 00:02:44.640 OK. 00:02:45.390 --> 00:02:54.350 So if you're a pretty page you can see that our message contains 11 words. 00:02:57.630 --> 00:02:58.410 OK. 00:02:58.410 --> 00:03:00.130 All right so let's define another. 00:03:00.420 --> 00:03:07.470 Let's echo another line break. 00:03:07.470 --> 00:03:08.980 All right. 00:03:09.960 --> 00:03:16.620 And this time we're going to try something different. 00:03:16.830 --> 00:03:24.940 So we are going to replace all the words Web sites with another word wilt. 00:03:25.120 --> 00:03:25.830 OK. 00:03:26.370 --> 00:03:27.840 So to do that 00:03:34.170 --> 00:03:36.670 we're going to use a function. 00:03:37.240 --> 00:03:39.240 OK let's echo this. 00:03:39.240 --> 00:03:45.340 So going to use a function s t or replace string replace. 00:03:45.840 --> 00:03:47.310 OK. 00:03:47.340 --> 00:03:53.540 This function is going to take a couple of parameters. 00:03:53.940 --> 00:03:54.600 So 00:03:57.720 --> 00:03:59.640 a few promises. 00:03:59.640 --> 00:04:00.060 OK. 00:04:00.210 --> 00:04:09.890 So we're going to have first the word we want to replace which is Web sites and then separating it with 00:04:09.890 --> 00:04:17.110 a comma we are going to have the word we want to use to replace the old one. 00:04:17.940 --> 00:04:30.360 And then after a comma we are going to place the string or the variable in question so we can add another 00:04:30.720 --> 00:04:32.130 variable if we want to. 00:04:32.680 --> 00:04:41.310 And this is another barometer of this part of it is going to store the number of words which have been 00:04:41.310 --> 00:04:42.210 replaced. 00:04:42.550 --> 00:04:51.660 Ok now I'm going to call it number of words replace. 00:04:52.190 --> 00:04:53.980 OK. 00:04:55.310 --> 00:04:55.710 Sorry. 00:04:55.720 --> 00:04:59.610 Read save and refresh the page 00:05:07.380 --> 00:05:11.850 . 00:05:12.890 --> 00:05:13.450 OK. 00:05:13.800 --> 00:05:20.840 So now we can see the value of or what the function has returned. 00:05:20.880 --> 00:05:27.020 So the function will just process all this and he's going to return the new value of message. 00:05:27.240 --> 00:05:27.720 So 00:05:31.030 --> 00:05:39.470 because he knows all the words Web sites they have been replaced by world wide. 00:05:41.280 --> 00:05:44.280 OK so if we Ecko message 00:05:47.690 --> 00:05:55.830 OK we'll see that message is still the old message. 00:05:55.830 --> 00:06:07.110 So the function string replace is not changing the variable message is just returning message with the 00:06:07.110 --> 00:06:07.690 changes. 00:06:07.740 --> 00:06:12.110 But the actual variable message is still the same. 00:06:12.130 --> 00:06:16.070 OK OK so let's take this away. 00:06:16.260 --> 00:06:25.410 So now let's have a let's have a break. 00:06:28.250 --> 00:06:29.640 OK. 00:06:30.150 --> 00:06:34.470 And now let's check this number of words are replaced. 00:06:34.870 --> 00:06:35.880 Going to echo 00:06:40.030 --> 00:06:46.820 number of words replaced. 00:06:47.170 --> 00:06:47.370 It 00:06:50.620 --> 00:06:51.870 is variable 00:06:55.150 --> 00:06:55.960 and it's odd 00:07:00.420 --> 00:07:02.240 where it's 00:07:08.220 --> 00:07:10.840 OK. 00:07:12.530 --> 00:07:17.440 So it has refreshed the page and you can see that we have replaced two words. 00:07:17.760 --> 00:07:19.980 OK. 00:07:19.980 --> 00:07:23.770 All right so one last function before we finish. 00:07:23.790 --> 00:07:25.680 Let's have a line break 00:07:28.980 --> 00:07:29.610 and 00:07:34.110 --> 00:07:40.020 let's use a function which is going to reverse our message. 00:07:40.140 --> 00:07:43.980 OK so it's going to echo a string. 00:07:44.100 --> 00:07:52.380 Can you read from the rights. 00:07:55.060 --> 00:07:55.360 OK 00:07:59.280 --> 00:08:03.070 let's have a library comes in. 00:08:04.570 --> 00:08:15.260 Let's add our message in the reverse way so we're going to use the function is C R A reverse. 00:08:15.710 --> 00:08:16.570 OK. 00:08:16.890 --> 00:08:18.270 And we're going to give is the 00:08:20.880 --> 00:08:23.930 message variable as a prose. 00:08:24.450 --> 00:08:26.630 Now if we refresh. 00:08:27.050 --> 00:08:34.080 You can see that's our message string now is reversed 00:08:34.090 --> 00:08:42.160 .