CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

04 January, 2019

Introduction to JavaScript Strings

 Programing Coderfunda     January 04, 2019     JavaScript, JavaScript Strings     No comments   

  JavaScript Strings

JavaScript में strings objects होती है। एक string object में characters की sequence store की जाती है। जैसे की Best Hindi Tutorials एक string है। Strings को double या single quotes में define किया जाता है।

जैसा की आपको पता है JavaScript dynamic और interactive web pages generate करने के लिए use की जाती है। यही reason है की JavaScript में strings को objects define किया गया है। Strings के objects होने से आप strings के presentation को page load होते समय अपने according control कर सकते है।

JavaScript web page में string representation को control करने के लिए आपको कई methods provide करती है। इन methods की मदद से आप आसानी से strings पर operations perform कर पाते है। इनके बारे में आपको आगे बताया जायेगा।

Creating JavaScript Strings

JavaScript में strings आप किसी भी normal variable की तरह create करते है। इसका general syntax निचे दिया जा रहा है। 
var stringName = "text";

जैसा की मैने आपको पहले बताया आप strings को single या double quotes में define करते है। इसलिए आप चाहे तो strings को single quotes में भी define कर सकते है।
var stringName = 'text';
JavaScript में strings create करना निचे उदाहरण द्वारा समझाया जा रहा है।
var name = "Best Hindi Tutorials";

Adding Special Characters to JavaScript Strings

मान लीजिये आप string में किसी word को double quotes में लिखना चाहते है तो इसके लिए आप उस text को double quote में इस प्रकार लिखेंगे। 
var name = "Best "Hindi" Tutorials";
लेकिन ये तरीका javascript के अनुसार ठीक नहीं है और इस तरीके से यदि आप double quotes add करेंगे तो आपको error show होगी। क्योंकि string पहले से ही double quotes में है इसलिए error generate होगी। इसी प्रकार यदि आप कोई backslash add करने का प्रयास करेंगे तो भी error show होगी।

JavaScript ऐसे ही कुछ characters को add करने के लिए आपको escape sequence characters provide करती है। इन characters की मदद से आप बिना error generate किये strings create कर सकते है।

JavaScript और दूसरी languages में backslash (\) के साथ escape sequence characters को define किया जाता है। Escape characters  से आप दूसरे special characters (@, $ आदि) भी strings में add कर सकते है।

Common javascript escape characters के बारे में निचे दिया जा रहा है।

Escape Characters 
Description
\'
String के अंदर single quote add करने के लिए। 
\"
String के अंदर double quotes add करने के लिए। 
\b 
String के अंदर backspace add करने के लिए। 
\r 
String के अंदर carriage return add करने के लिए। 
\f 
String के अंदर form feed add करने के लिए। 

Length Property 

JavaScript आपको length property provide करती है जिससे आप किसी भी string की length पता कर सकते है। इस property को आप string name के साथ dot (.) operator लगाकर use करते है। इसका syntax निचे दिया जा रहा है। 
stringName.length;

इसका उदाहरण निचे दिया जा रहा है।
<!-- javascriptLengthProperty.html -->

<html>
<body>

<script type="text/javascript">
var BHT = "Best Hindi Tutorials";
// Printing length of string
document.write(BHT.length);
</script>

</body>
</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
20 

Common String Methods

Strings के साथ advance level पर work करने के लिए JavaScript आपको बहुत से useful methods provide करती है। सभी method string object के साथ dot operator (.) लगाकर call किये जाते है। यँहा पर एक बात ध्यान रखना बहुत ही जरुरी है की सभी strings की index zero से शुरू होती है।

कुछ common javascript string methods के बारे में निचे दिया जा रहा है।

charAt()

ये method pass की गयी position पर available character को return करता है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- charatMethodDemo.html -->

<html>

<script type="text/javascript">
var name = "Vipin";
// Printing character at position 1
var result = name.charAt(1);
document.write(result);
</script>

</html>

ऊपर दी गयी script निचे दिया गया output generate करती है।
i 

concat() 

ये method दो strings को combine करके return करता है। इसे किसी एक string पर call किया जाता है और दूसरी string इसमें pass की जाती है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- concatMethodDemo.html -->

<html>

<script type="text/javascript">
var fname = "Vipin "
var lname = "Sharma";
// Concatenating first name and last name
var result = fname.concat(lname);
document.write(result);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
Vipin Sharma

endsWith()

ये method check करता है की string pass किये गए character या string से end होती है या नहीं। इसका उदाहरण निचे दिया जा रहा है। 
<!-- endWithMethodDemo.html -->

<html>

<script type="text/javascript">
var BHT = "Best Hindi Tutorials";
// Checking what a string ends with.
var result = BHT.endsWith("Tutorials");
document.write(result);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
true

includes()

ये method check करता है की किसी string में pass किया गया character या string है या नहीं। इसका उदाहरण निचे दिया गया रहा है। 
<!-- includesMethodDemo.html -->

<html>

<script type="text/javascript">
var name = "Best Hindi Tutorials";
// Checking if a string includes a word.
var result = name.includes("Hindi");
document.write(result);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
true

indexOf()

ये method pass की गयी string की position return करता है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- indexOfMethodDemo.html -->

<html>

<script type="text/javascript">
var bht = "Best Hindi Tutorials";
// Getting starting index of a word.
var result = bht.indexOf("Hindi");
document.write(result);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
5 

search()

ये method एक string को pass की गयी value के लिए search करता है। यदि pass की गयी value मिल जाती है तो इस function द्वारा उसकी position return की जाती है। इसका उदाहरण निचे दिया जा रहा है। 

<!-- searchMethodDemo.html -->

<html>

<script type="text/javascript">
var str = "Best Hindi Tutorials";
// Searching starting index of a word.
var result = str.search("Tutorials");
document.write(result);
</script>

</html>

ऊपर दी गयी script निचे दिया गया output generate करती है।

11

replace()

ये method एक string में से pass की गयी string को replace करके उसकी जगह second argument वाली string को place करता है और complete string को return करता है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- replaceMethodDemo.html -->

<html>

<script type="text/javascript">
var bht = "Best Hindi Tutorials Ever";
// Replacing a word
var result = bht.replace("Hindi"," ");
document.write(result);
</script>

</html>

ऊपर दी गयी script निचे दिया गया output generate करती है।
Best Tutorials Ever

substr()

ये method एक string में से substring extract करके return करता है। जिस substring को आप extract करना चाहते है उसके starting index number को आप first index के रूप में pass करते है और second argument में आप उन characters की सँख्या pass करते है जिन्हे आप starting index के बाद से extract करना चाहते है।

इसका उदाहरण निचे दिया जा रहा है।
<!-- substrMethodDemo.html -->

<html>

<script type="text/javascript">
var bht = "Best Hindi Tutorials";
// Getting substring from a string
var result = bht.substr(5,5);
document.write(result);
</script>

</html>

ऊपर दी गयी script निचे दिया गया output generate करती है।
Hindi 

toLowerCase()

ये method string के सभी characters को lowercase में convert करता है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- toLowerCaseMethodDemo.html -->

<html>

<script type="text/javascript">
var bht = "BEST HINDI TUTORIALS";
// Converting string to lowercase
var result = bht.toLowerCase();
document.write(result);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।
best hindi tutorials

toUpperCase()

ये method string के सभी characters को uppercase में convert करता है। इसका उदाहरण निचे दिया जा रहा है। 
<!-- toUpperCaseMethodDemo.html -->

<html>

<script type="text/javascript">
var str = "best hindi tutorials";
// Converting string to upper case
var res = str.toUpperCase();
document.write(res);
</script>

</html>
ऊपर दी गयी script निचे दिया गया output generate करती है।

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • JavaScript Operators JavaScript Operators Variables में values सिर्फ उन्हें बाद में display करवाने के लिए ही नहीं बल्कि इसलिए भी store की जाती है  ताकि उनके साथ… Read More
  • Introduction to JavaScript Control Statements JavaScript Control Statements In HindiControl statements program के flow को control करते है। जैसे की आप control statements की मदद से choose कर सकते ह… Read More
  • Introduction to JavaScript ArraysJavaScript Arrays in HindiArrays एक ही तरह की values का collection होता है। एक तरह की value से मतलब है या तो केवल strings या केवल integers या फिर flo… Read More
  • JavaScript Variables Introduction to JavaScript Variables यदि आपको कोई value store करनी है तो इसके लिए आपको variable create करना होता है। ये concept सभी programming … Read More
  • JavaScript SyntaxIntroduction to JavaScript Syntax  किसी भी HTML program में JavaScript को add करना बहुत ही आसान है। इसके लिए आप <script> tag यूज़ करते है।… Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh
    I had follow these steps to install an configure firebase to my cordova project for cloud messaging. https://medium.com/@felipepucinelli/how...
  • Spring boot app (error: method getFirst()) failed to run at local machine, but can run on server
    The Spring boot app can run on the online server. Now, we want to replicate the same app at the local machine but the Spring boot jar file f...
  • Step-by-step guide to linking gnuplot to Octave within Virtual Studio Code (VSC)
    I am aware of a number of previous questions (here, here and here for example) pointing out to the need to modify a file named .octaverc. ...
  • Log activity in a Laravel app with Spatie/Laravel-Activitylog
      Requirements This package needs PHP 8.1+ and Laravel 9.0 or higher. The latest version of this package needs PHP 8.2+ and Laravel 8 or hig...
  • SQL Tutorial
    SQL Tutorial SQL HOME SQL Intro SQL Syntax SQL Select SQL Select Distinct SQL Where SQL And, Or, Not SQL Order By SQL Insert Into SQL Null V...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • NativePHP Hit $100K — And We're Just Getting Started 🚀 - 5/8/2025
  • Name Queued Closures in Laravel 12.13 - 5/8/2025
  • Simplify HasManyThrough Relationships with Laravel's CanBeOneOfMany Support - 5/4/2025
  • Using Database Comments to Track Columns With Sensitive Data - 5/7/2025
  • Accelerate API Testing with Laravel's ddBody() Method - 5/4/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda