0% found this document useful (0 votes)
7 views3 pages

Advance Angular Lecture 3

Uploaded by

varshilbhojakpr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Advance Angular Lecture 3

Uploaded by

varshilbhojakpr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Advance Angular v.

17
3. String Functions - 1

MANIPULATING FUNCTIONS
Manipulating functions in string functions in Angular typically refers to the process of working with string
values within Angular components or services. String manipulation functions in Angular can involve tasks
such as concatenating strings, splitting strings, extracting substrings, replacing parts of strings, converting
strings to different cases (e.g., uppercase, lowercase), and more.

HTML—
<div>
<button (click)="splitString()">Split</button>
<button (click)="replaceString()">Replace</button>
<button (click)="repeatString()">Repeat</button>
<button (click)="concatenateStrings()">Concatenate</button>
<button (click)="trimString()">Trim</button>
<button (click)="toUpperCase()">To Uppercase</button>
<button (click)="toLowerCase()">To Lowercase</button>
<button (click)="getSubstring()">Substring</button>
<button (click)="getSubstr()">Substr</button>
<button (click)="getCharAt()">Char At</button>
</div>

TS—
original String: string = "Hello, World!";
splitString():
Splits the original string into an array of substrings based on the specified separator (,). Each substring is
stored as an element in the resulting array.

splitString() {
// Splits the string into an array of substrings based on a specified
separator
let substrings: string[] = this.originalString.split(',');
console.log(substrings);
}

Output: ["Hello", " World!"]


replaceString():
Replaces the first occurrence of the substring 'World' with 'Universe' in the original string and returns the
modified string.
replaceString() {
// Replaces a specified value or pattern in a string with another value
let newString: string = this.originalString.replace('World', 'Universe');
console.log(newString);
}

1
Advance Angular v.17
3. String Functions - 1

Output: Hello, Universe!


repeatString():
Creates a new string by repeating the original string three times, as specified by the parameter, and returns
the concatenated result.
repeatString() {
// Returns a new string with a specified number of copies of the
original string concatenated together
let repeatedString: string = this.originalString.repeat(3);
console.log(repeatedString);
}

Output: Hello, World!Hello, World!Hello, World!

concatenateStrings():
Concatenates the original string with the specified string ' Have a nice day!' and returns the combined
string.

concatenateStrings() {
// Concatenates two or more strings and returns a new string
let concatenatedString: string = this.originalString.concat(' Have a
nice day!');
console.log(concatenatedString);
}

Output: Hello, World! Have a nice day!

trimString():
Removes any leading and trailing whitespace characters from the original string and returns the trimmed
string.

trimString() {
// Removes whitespace from both ends of a string
let trimmedString: string = this.originalString.trim();
console.log(trimmedString);
}

Output: Hello, World!

toUpperCase():
Converts all characters in the original string to uppercase letters and returns the modified string.

toUpperCase() {
// Converts a string to uppercase letters
let upperCaseString: string = this.originalString.toUpperCase();
console.log(upperCaseString);
}

2
Advance Angular v.17
3. String Functions - 1

Output: HELLO, WORLD!

toLowerCase():
Converts all characters in the original string to lowercase letters and returns the modified string.

toLowerCase() {
// Converts a string to lowercase letters
let lowerCaseString: string = this.originalString.toLowerCase();
console.log(lowerCaseString);
}

Output: hello, world!

getSubstring():
Extracts a substring from the original string starting at index 7 and ending at index 12 (exclusive) and
returns the extracted substring.

getSubstring() {
// Returns a substring of a string between two specified indices
let substring: string = this.originalString.substring(7, 12);
console.log(substring);
}

Output: World

getSubstr():
Retrieves a substring from the original string starting at index 7 with a length of 5 characters and returns
the extracted substring.

getSubstr() {
// Returns a portion of a string starting from a specified index to the
end of the string, or to a specified length
let substr: string = this.originalString.substr(7, 5);
console.log(substr);
}

Output: World

getCharAt(): Retrieves the character at index 7 in the original string and returns it.

getCharAt() {
// Returns the character at a specified index in a string
let char: string = this.originalString.charAt(7);
console.log(char);
}

Output: W

You might also like