0

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])
1

3 Answers 3

1
  1. Use TextField to retrieve user's input:

A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.

  1. Use Text to display the string that you retrieve:

The Text widget displays a string of text with single style.

  1. Use the [] (index) operator to get the character at the index you specify:
final str = "Hello World";

print(str[4]); // Prints o
Sign up to request clarification or add additional context in comments.

Comments

0

You can try split the string's letters in an array first.

my_word.split('')[4]

Comments

0

dartPad

main() {
  String val = "hello";
  print(val[4]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.