Aktualisiert: v2.5
Hallo zusammen,
ich hätt' da mal 'ne Frage (sonst würde ich auch wohl nicht posten ^^) :
Hab schon mein Gehirn und Suchmaschienen gequält, aber nichts gefunden.
Ich bin auf der Suche nach einer String-Matching Funktion. Also im Stil von:
bool string_match (string subject, string match)
Als Beispiele wäre da:
subject: test.gmk
match: *.gmk
return: true
subject: Wenn Abfrage Dann Anweisung Sonst Anweisung
match: Wenn * Dann * Sonst *
return: true
subject: OhneIrgendwas Leerzeichen
match: Ohne * Leerzeichen
return: false
subject: ***
match: ***
return: true
Beispiele Funktionieren jetzt!
Aktueller Code v2.5
Alles anzeigen
mfg,
swffilms
Hallo zusammen,
ich hätt' da mal 'ne Frage (sonst würde ich auch wohl nicht posten ^^) :
Hab schon mein Gehirn und Suchmaschienen gequält, aber nichts gefunden.
Ich bin auf der Suche nach einer String-Matching Funktion. Also im Stil von:
bool string_match (string subject, string match)
Als Beispiele wäre da:
subject: test.gmk
match: *.gmk
return: true
subject: Wenn Abfrage Dann Anweisung Sonst Anweisung
match: Wenn * Dann * Sonst *
return: true
subject: OhneIrgendwas Leerzeichen
match: Ohne * Leerzeichen
return: false
subject: ***
match: ***
return: true
Beispiele Funktionieren jetzt!
Aktueller Code v2.5
GML-Quellcode
- var subject, match, temp, pos;
- subject = argument0;
- match = argument1;
- temp = true;
- for (pos = 0; (temp == true && pos < string_length(match)); pos += 1)
- {
- if (string_char_at(match, pos) != "*")
- {
- temp = false;
- }
- }
- if (temp == true)
- {
- return true;
- }
- if (string_char_at(match, 1) == "*")
- {
- match = string_copy(match, 2, string_length(match) -1 );
- if (string_count("*", match) >= 1)
- {
- temp = string_copy(match, 1, string_pos("*", match) -1 );
- }
- else
- {
- temp = match;
- }
- subject = string_copy(subject, string_pos(temp, subject) +0 , string_length(subject));
- }
- repeat (string_count("*", match) +1)
- {
- if (string_count("*", match) == 0)
- {
- if (match == string_copy(subject, string_length(subject)-string_length(match)+1, string_length(match)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- temp = string_copy(match, 1, string_pos("*", match) -1 );
- pos = string_pos(temp, subject);
- if (pos == 1)
- {
- subject = string_copy(subject, string_length(temp) +1 , string_length(subject));
- match = string_copy(match, string_pos("*", match), string_length(match));
- }
- else
- {
- return false;
- }
- if (string_char_at(match, 1) == "*")
- {
- match = string_copy(match, 2, string_length(match) -1 );
- if (string_count("*", match) >= 1)
- {
- temp = string_copy(match, 1, string_pos("*", match) -1 );
- }
- else
- {
- temp = match;
- }
- subject = string_copy(subject, string_pos(temp, subject) +0 , string_length(subject));
- }
- }
- return false;
mfg,
swffilms
Dieser Beitrag wurde bereits 6 mal editiert, zuletzt von swffilms ()