How would I find the min and max number in a textEdit of comma spaces integers without using the built in functions?

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

For instance, I would need to process the array to find both the min and max numbers in a list of integers that the user inputs into a text edit. Thanks!

So, a User will type a single string into a TextEdit control, consisting of integers separated by commas (and possibly spaces?) and you want to find the min and max integer values in that string?

For example, your string might look like this?

52, 27, 16,44,19, 55, 122

Is that correct? Much of the difficulty with string parsing is understanding the possible content of the target string. For example, will all values be separated by commas, or might they also just be separated by spaces? Could there be multiple commas between consecutive values? Can there be multiple spaces? Can the spaces be missing or are they required?

Please provide some examples of the expected string contents.

On the surface, I assume this is likely a good candidate for some regex parsing…

jgodfrey | 2022-12-05 23:11

:bust_in_silhouette: Reply From: jgodfrey

Here’s a working regex-based solution:

func _ready():
	var values = []
	var regex =
	for result in regex.search_all("13, 14, 16, 17, 9, 2, 18"):
	print("All values: %s" % [values])
	print("Min: %s" % [values.min()])
	print("Max: %s" % [values.max()])