Reputation: 89
I would like to access an index of a string (e.g. 'Hello') and print it to the app (e.g. letter 'o'). This string has to be the input of the user. This can be easily done using Python but I have to use Flutter/Dart in order to do it (mobile development).
Here is just an example of how this would be solve using Python:
my_word = input("Insert your word here: ")
print(my_word[4])
Upvotes: 0
Views: 1365
Reputation: 5638
TextField
to retrieve user's input:A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.
Text
to display the string that you retrieve:The Text widget displays a string of text with single style.
[]
(index) operator to get the character at the index you specify:final str = "Hello World";
print(str[4]); // Prints o
Upvotes: 1
Reputation: 4726
You can try split the string's letters in an array first.
my_word.split('')[4]
Upvotes: 0