Vinhtrinh - Tin Tức Hay, Siêu Hot Cập Nhật Hàng Ngày
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính
No Result
View All Result
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính
No Result
View All Result
Vinhtrinh - Tin Tức Hay, Siêu Hot Cập Nhật Hàng Ngày
No Result
View All Result

Strings in JavaScript

admin by admin
May 20, 2020
in Công Nghệ
25
Strings in JavaScript



Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

In this video we will discuss different functions that are available to manipulate string in JavaScript.

A string is any text inside quotes. You can use either single or double quotes.
var string1 = “string in double quotes”
var string2 = ‘string in single quotes’

Concatenating strings : There are 2 options to concatenate strings in JavaScript. You could either use + operator or concat() method

Example : Concatenating strings using + operator
var string1 = “Hello”
var string2 = “JavaScript”
var result = string1 + ” ” + string2;
alert(result);

Output : Hello JavaScript

Example : Concatenating strings using concat() method
var string1 = “Hello”
var string2 = “JavaScript”
var result = string1.concat(” “, string2);
alert(result);

Output : Hello JavaScript

If you want single quotes inside a string, there are 2 options
Option 1 : Place your entire string in double quotes, and use single quotes inside the string wherever you need them.

Example :
var myString = “Welcome to ‘JavaScript’ Training”;
alert(myString);

Output : Welcome to ‘JavaScript’ Training

Option 2 : If you prefer to place your entire string in single quotes, then use escape sequence character with a single quote inside the string.

Example :
var myString = ‘Welcome to ‘JavaScript’ Training’;
alert(myString);

Output : Welcome to ‘JavaScript’ Training

Please Note : You can use the above 2 ways if you need double quotes inside a string

Converting a string to uppercase : Use toUpperCase() method

Example :
var upperCaseString = “JavaScript”;
alert(upperCaseString.toUpperCase());

Output : JAVASCRIPT

Converting a string to lowercase : Use toLowerCase() method

Example :
var lowerCaseString = “JavaScript”;
alert(lowerCaseString.toLowerCase());

Output : javascript

Length of string javascript : Use length property

Example : alert(“JavaScript”.length);

Output : 10

Example :
var myString = “Hello JavaScript”;
alert(myString.length);

Output : 16

Remove whitespace from both ends of a string : Use trim() method

Example :
var string1 = ” AB “;
var string2 = ” CD “;
var result = string1.trim() + string2.trim();
alert(result);

Output : ABCD

Replacing strings in javascript : Use replace() method. This method searches a given string for a specified value or a regular expression, replaces the specified values with the replacement values and returns a new string. This method does not change the original string.

Example : Replaces JavaScript with World
var myString = “Hello JavaScript”;
var result = myString.replace(“JavaScript”, “World”);
alert(result);

Output : Hello World

Example : Perform a case-sensitive global replacement. In this example, we are using a regular expression between the 2 forward slashes(//). The letter g after the forward slash specifies a global replacement. The match here is case sensitive. This means Blue(with capital B) is not replaced with green.

var myString = “A Blue bottle with a blue liquid is on a blue table”;
var result = myString.replace(/blue/g, “green”);
alert(result);

Output : A Blue bottle with a green liquid is on a green table

Example : Perform a case-insensitive global replacement. The letters gi after the forward slash indicates to do global case-insensitive replacement. Notice that the word Blue(with capital B) is also replaced with green.

Nguồn: https://vinhtrinh.com.vn

Xem thêm bài viết khác: https://vinhtrinh.com.vn/cong-nghe/

Xem thêm Bài Viết:

  • Dash là gì? Tìm hiểu chi tiết về đồng tiền ảo Dashcoin
  • Top 3 ứng dụng xem phim online chất lượng cao trên di động
  • Giải pháp thiết kế website in ấn chuyên nghiệp, giá rẻ và chuẩn SEO
  • Khách hàng mục tiêu là gì và cách để xác định khách hàng mục tiêu hiệu quả
  • Growth hacking là gì? Làm sao để trở thành growth hacker
Previous Post

Google Lens - How to use Google Lens - Google Lens tips and tricks 2019 Hindi

Next Post

Cổ phiếu FPT sụt giảm, chứng khoán châu Á tràn sắc đỏ | FBNC TV Giờ Kết Sổ 14/11/19

Next Post
Cổ phiếu FPT sụt giảm, chứng khoán châu Á tràn sắc đỏ | FBNC TV Giờ Kết Sổ 14/11/19

Cổ phiếu FPT sụt giảm, chứng khoán châu Á tràn sắc đỏ | FBNC TV Giờ Kết Sổ 14/11/19

Comments 25

  1. Purna Mahesh says:
    2 years ago

    var a = "mahesh";

    var b = "naresh";

    for(var i=0;i<a.length;i++){

    for(var j=0;j<b.length;j++){

    if(a.charAt(i)==b.charAt(j)){

    a.replace(a.charAt(i),'');

    b.replace(b.charAt(j),'');

    i–;

    break;

    }

    }

    }

    document.write("<h2>"+a+" "+b+"</h2>");

    why this js program isn't working

    Reply
  2. Aditya Chauhan says:
    2 years ago

    Thank you for detailed and easy explanations

    Reply
  3. MAHESH SUTAR says:
    2 years ago

    Very nice tutorial series! Much in depth knowledge about javascript programming! Thanks a lot!!!
    Will you please make a tutorial series on Java?

    Reply
  4. nayan parmar says:
    2 years ago

    Thanks

    Reply
  5. Rucha Warhekar says:
    2 years ago

    thank u sir

    Reply
  6. Chakka Varikka says:
    2 years ago

    /* Thanks */
    /* Replace ALL */

    a="12-02-2018";
    bb=a.replace(/-/g,'=');
    alert(bb);

    Reply
  7. Rukesh Reddy says:
    2 years ago

    Thank u so much Sir

    Reply
  8. chandu kumar says:
    2 years ago

    how to deal with variable

    —————————————
    var myString = "A Blue bottle with a blue liquid is on a blue table";
    var name='blue';
    var result = myString.replace(/'name'/g, "green");
    alert(result);

    Reply
  9. HIMEL SARKAR says:
    2 years ago

    Explain it String s = string2.trim(); ????????????

    Reply
  10. Naveed Riaz says:
    2 years ago

    I watched your few videos you are great teacher

    Reply
  11. kingsley chibuzor says:
    2 years ago

    Thank you sir

    Reply
  12. mahmoud elkout says:
    2 years ago

    excellent

    Reply
  13. Neddih Lous says:
    2 years ago

    pure awesome;

    Reply
  14. Vignesh Ravichandran says:
    2 years ago

    You do all explanations very good and with proper speed. Thanks man, you helped me a lot

    Reply
  15. Hakan Koluaçık says:
    2 years ago

    You do all explanations very good and with proper speed. Thanks man, you helped me a lot

    Reply
  16. Amit Sharma says:
    2 years ago

    Nice way to explain

    Reply
  17. RAQIBUL ALAM RASHED says:
    2 years ago

    Thanks abillions.

    Reply
  18. LuqMaN AFridi says:
    2 years ago

    excellent mehtod !!!
    I m very thankful of U Sir >>>

    Reply
  19. Hashmat Rai says:
    2 years ago

    amazing very clear explanation..thank you sir 🙂

    Reply
  20. sd says:
    2 years ago

    YOU'RE THE BEST+EST ! Thanks!

    Reply
  21. Cool Picks says:
    2 years ago

    clear easy explanation. to-the-point. full of practical examples & applications of javascript.. Thank u very much Venkat

    Reply
  22. MrRicardo141 says:
    2 years ago

    This guy covers everything. FANSTASTIC!

    Reply
  23. Alejandro Rincon says:
    2 years ago

    Great tutorial thank you very much

    Reply
  24. Sudeep Makwana says:
    2 years ago

    Thanks for video +kudvenkat  

    Reply
  25. kaminari66 says:
    2 years ago

    Great video!  You may want to note that string.trim() is not supported in older IE versions such as IE8.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Xem Thêm

Dự án căn hộ chung cư Grand Prime Bình Chánh

Dự án căn hộ chung cư Grand Prime Bình Chánh

June 17, 2022
Thông tin dự án chung cư Thanh Bình Plaza

Thông tin dự án chung cư Thanh Bình Plaza

June 16, 2022
nhà riêng bình tân

Vì sao nên thuê nhà ở Quận Bình Tân

June 15, 2022
Dự án Căn hộ Midori Park The Glory Bình Dương

Dự án Căn hộ Midori Park The Glory Bình Dương

June 14, 2022
Dự án Thuận An Central nằm giữa những trục đường giao thông lớn kết nối vùng thuận tiện

Thuận An Central Bình Dương mới nhất 2022

June 9, 2022
Căn hộ Rubi Homes huyện Bình Chánh

Căn hộ Rubi Homes huyện Bình Chánh

June 9, 2022
  • Liên Hệ
  • Chính Sách Bảo Mật

© 2022 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính

© 2022 JNews - Premium WordPress news & magazine theme by Jegtheme.