आपकी ऑफलाइन सहायता

BACK
49

सी प्रोग्रामिंग

149

पाइथन प्रोग्रामिंग

49

सी प्लस प्लस

99

जावा प्रोग्रामिंग

149

जावास्क्रिप्ट

49

एंगुलर जे.एस.

69

पी.एच.पी.
माय एस.क्यू.एल.

99

एस.क्यू.एल.

Free

एच.टी.एम.एल.

99

सी.एस.एस.

149

आर प्रोग्रामिंग

39

जे.एस.पी.





डाउनलोड पी.डी.एफ. ई-बुक्स
JS - String

String ये Characters का sequence होता है |

String को single या double quotes के अन्दर लिखा जाता है |

var str1 = 'Hello';
var str2 = "World";

Empty String

var str3 = "";

Strings को दो प्रकार से create किये जाते है |

  • String Type
  • String Object Type
var str4 = "Hello World"; //String Type
var str5 = new String("Hello World"); //String Object Type

Check Strings Equal or Not using '==' Operator

'==' Operator से दोनों Strings equal है |

Source Code :

Output :
true

Check Strings Equal or Not using '==' Operator

'===' Operator से दोनों Strings equal नहीं है, क्योंकि उनके data types अलग-अलग है |

Source Code :

Output :
false

निचे दिए हुए Example में देखे तो double quoted String में double quoted String दिया हुआ है | इससे String access नहीं होता |

var str = "Hello Friends! My name is "Rakesh"";
	document.write(str);

यदि double quoted string के अन्दर single quoted और single quoted string के अन्दर double quoted string हो तो वो access हो जाता है |

Source Code :

Output :
Hello Friends! My name is 'Rakesh'
Hello Friends! My name is "Rakesh"

अगर single quoted string के अन्दर single quoted string और double quoted string के अन्दर double quoted strig को access करने के लिए पहले escape character (\) का इस्तेमाल करना पड़ता है |

अगर String में special characters को executes करना हो तो special characters से पहले escape character(\) का इस्तेमाल करना पड़ता है |

Source Code :

Output :
Hello Friends! My name is "Rakesh"
Hello Friends! My name is 'Rakesh'

String Length Property

String की length ये बहुत ही महत्वपूर्ण property है |

Source Code :

Output :
11

Javascript में String के लिए कुछ methods दिए गए है |

String MethodsDescription
charAt()दिए हुए index का character return करता है |
charCodeAt()दिए हुए index के character की Unicode value में return करता है |
concat()दो string या दो से ज्यादा string को जोड़ने के लिए इस्तेमाल किया जाता है |
endsWith()दिए हुए String या character से String का end हुआ है या नहीं हुआ है इससे boolean value को return करता है |
fromCharCode()दिए हुए Unicode value से character को return करता है |
indexOf()दिए हुए characters का first occurrence का index return किया जाता है |
lastIndexOf()दिए हुए characters का last occurrence का index return किया जाता है |
localeCompare()दो String को locale में compare किया जाता है | ये 0, 1 या -1 return करता है |
repeat()दिए हुए number तक String को repeat करके return किया जाता है |
replace()दिए हुए string से substring को regular expression से या नए string से replace किया जाता है |
search()दिए हुए regular expression या string को search करके उसका index return किया जाता है | अगर search नहीं होता तो -1 return होता है |
slice()दिए हुए startindex से endindex तक नए String को return किया जाता है |
split()दिए हुए character से string को split करके array return किया जाता है |
startsWith()String की शुरुआत दिए हुए character या substring से हुई है या नहीं हुई है ये boolean value में return किया जाता है |
substr()String से दिए हुए index से उसके दिए हुए length तक substring को return किया जाता है |
substring()String से दिए हुए startindex से endindex तक substring को return किया जाता है |
toLowercase()दिए हुए String को lowercase में return किया जाता है |
toString()दिए हुए string object को string में return किया जाता है |
toUpperCase()दिए हुए String को uppercase में return किया जाता है |
trim()String से शुरुआत और आखिर के spaces को trim किया जाता है |