String Interpolation
/// Flutter is Google's portable UI toolkit for crafting beautiful,
/// natively compiled applications for mobile, web, and desktop from a single codebase.
/// String Interpolation
//String interpolation is the process of inserting variable values into placeholders in a string literal.
//To concatenate strings in Dart, we can utilize string interpolation.
// We use the ${} symbol to implement string interpolation in your code.
//void main() {
/// Assigning values to the variable
// String shot1 = "String";
// String shot2 = "interpolation";
// String shot3 = "in";
// String shot4 = "Dart programming";
/// Concatenate all values using string interpolation without space
//print("$shot1$shot2$shot3$shot4");
/// Concatenate all values using string interpolation with space
// print("\n");
// print("Now include space between each value");
// print("\n");
// print("$shot1 $shot2 $shot3 $shot4");
//}
//To interpolate the value of Dart expressions within strings, use ${}.
// The curly braces {} are skipped if the expression is an identifier.
// void main() {
// String text = "Educative";
// // text is an identifier so the {} can be omitted
// print("The word $text has ${text.length} letters");
// }
/// The Example below uses string interpolation in a list and map operation.
// void main() {
// List mylist = [10, 20, 30, 40, 50, 60];
// // Using map on list items
// List newlist = [mylist.map((i){ return i * i;})];
//
// print("The list $mylist was squared to give a new list $newlist");
//
// /// Creating Map items
// Map myMap = {"1" : "String", "2" : "literals"};
//
// print("This is a shot on ${myMap["1"]} Interpolation");
// }
// void main() {
// var arr = ["a", "b", "c", "d", "e"];
// print(arr.first); //It returns the first element of the array.
// print(arr.last); //It returns the last element of the array.
// print(arr.isEmpty); //It returns true if the list is empty; otherwise, it returns false
// print(arr.length); //It returns the length of the array
// }
// void main() {
// var myList= [1,2,3,4,5];
//
// //sublist():
// //This method returns a new list containing elements from index between start and end.
// // Note that end element is exclusive while start is inclusive.
// print(myList.sublist(1,3));
//
// print(myList.sublist(1));//If end parameter is not provided, it returns all elements starting from start till length of the list.
//
// myList.shuffle();
// print("$myList"); //This method re-arranges order of the elements in the given list randomly.
// }
Comments
Post a Comment