Created
March 15, 2025 01:12
-
-
Save gilzoide/f6ef62c2a46af140d017af0fc280f91a to your computer and use it in GitHub Desktop.
Common prefix for 2 strings in GDScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Get common prefix for 2 strings | |
static func get_common_string_prefix(s1: String, s2: String) -> String: | |
var common_length = min(s1.length(), s2.length()) | |
for i in range(common_length): | |
if s1[i] != s2[i]: | |
return s1.substr(0, i) | |
return s1.substr(0, common_length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment