Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating content for string in dsa folder #124

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 143 additions & 4 deletions content/batch/dsa/string.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,148 @@
---
title: String
description: Learn String in JavaScript
title: Strings
description: Learn Strings in JavaScript
---

<Callout>
Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website).
</Callout>
## What's on this section?

In this section, you will:

- 🎨 Explore different string manipulation techniques in JavaScript.
- 🔍 Understand the various string methods and their usage.
- 💡 Learn about template literals and string interpolation.
- 🚀 Practice your knowledge through assignments related to string manipulation.

<Tabs defaultValue="learn">

<TabsList>
<TabsTrigger value="learn">Learn</TabsTrigger>
<TabsTrigger value="assignment">Assignment</TabsTrigger>
</TabsList>

<TabsContent value="learn">

## 📺 Watch Now

<div className="w-full h-full">
<a href="https://www.youtube.com/watch?v=Unc365YFdf4" >
<img className="w-full h-full object-cover" src="https://camo.githubusercontent.com/266a84400260b3b6aa0d97332a19d301ee8f767d229083dfd58931781efea309/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f556e6333363559466466342f302e6a7067" alt="JavaScript Loops" />
Copy link
Member

@Vishal-raj-1 Vishal-raj-1 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the src you have to add youtube video id, which is Unc365YFdf4 in this case.

http://img.youtube.com/vi/{YouTube_id}/0.jpg

so img tag will be like this

<img className="w-full h-full object-cover" src="http://img.youtube.com/vi/Unc365YFdf4/0.jpg" alt="Strings in JavaScript" />

</a>
</div>

<Callout type="info">
We hope that you found the tutorial video helpful in understanding the basic concepts of Strings in java, You can refer this notes 📝 for quick revision.
</Callout>

## 📝 Study Notes

# String In JavaScript


### Length of a String
```javascript
let firstName = "Vaishali";
console.log(firstName.length);
```

### Access String Element
```javascript
console.log(firstName.charAt(2)); // i
console.log(firstName[2]); // i
console.log(firstName.charCodeAt(2)); // 115 (Ascii Code)
```

### Check Presence of Character
```javascript
console.log(firstName.includes("r")); // false (& if present it return true)
console.log(firstName.indexOf("i")); // 2 (& if not present it return -1)
console.log(firstName.lastIndexOf("i")); // 7
```

### Compare Two Strings
```javascript
let anotherName = "Vishal";
console.log(firstName.localeCompare(anotherName)); // -1 (& if strings are equal it return 0)
```

### Replace Substring
```javascript
const str = "Vishal is Best Frontend Developer. Vishal is Best Developer. ";
console.log(str.replace("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Vishal is Best Developer. "
console.log(str.replaceAll("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Sujit is Best Developer. "
```

### Substring of a String
```javascript
console.log(str.substring(6, 30));
console.log(str.slice(-10, -1));
```

### Split and Join
```javascript
console.log(str.split(""));
const subString = str.split(" ");
console.log(subString.join(" "));
```

### String Start and End
```javascript
console.log(str.startsWith("Vishal")); // true
console.log(str.endsWith("Developer")); // true
```

### Trim and Case Conversion
```javascript
const trimStr = str.trim();
const trimStrStart = str.trimStart();
const trimStrEnd = str.trimEnd();
console.log(trimStr, trimStr.length);
console.log(str.toLowerCase());
console.log(str.toUpperCase());
```

### Convert Number and Object to String
```javascript
const num = 123;
console.log(num, num.toString());

const obj = {
name: "Vishal",
course: "DSA with Vishal"
};
console.log(obj, JSON.stringify(obj));
```

### Concatenate Strings
```javascript
const lastName = "Rajput";
console.log(firstName + lastName);
console.log(`${firstName} ${lastName} is a Best Developer`);
console.log(firstName.concat(lastName, " is a", " Best"));
```


</TabsContent>

<TabsContent value="assignment">
## Practice Questions

- [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/)
- [Reverse String](https://leetcode.com/problems/reverse-string)
- [Valid Anagram](https://leetcode.com/problems/valid-anagram)
- [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix)
- [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately)
- [Length of Last Word](https://leetcode.com/problems/length-of-last-word/)
- [Valid Palindrome](https://leetcode.com/problems/valid-palindrome)
- [String Compression](https://leetcode.com/problems/string-compression)
- [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string)
- [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string)
- [Rotate String](https://leetcode.com/problems/rotate-string)

</TabsContent>


</Tabs>

Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website).
</Callout>