How can I call a group of array from a .txt file that is starting from the letter of my current word?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Immanity

For example I have a text file in .txt format:
1.acerola
2.apple
3.banana
4.blueberry
5.breadfruit
6.cantaloupe
7.carambola

I want to print all the words starting from the letter a. How can I do that?

:bust_in_silhouette: Reply From: volzhs
func _ready():
	read("res://words.txt", "a")

func read(p_path, p_starts_with):
	var file = File.new()
	var err = file.open(p_path, file.READ)
	
	if err != OK:
		print("Can't read ", p_path)
		return
	
	while !file.eof_reached():
		var line = file.get_line()
		if line.find(".") < 0:
			continue
		var split = Array(line.split("."))
		var word = split[1]
		if word.begins_with(p_starts_with):
			print(word)
	
	file.close()

thank you very much

Immanity | 2019-09-13 16:45

when i type the code you send, I didn’t get any output but it didn’t say it’s an error
what do you think is the problem?

Immanity | 2019-09-13 17:17

utf8 encoding for txt file maybe?

volzhs | 2019-09-13 20:13