String Tokenizer
#8
Ok, I have get this right now. Let's see if this can also be integrated into Basic. That would be good, because in QB64 it's far too complicated.

In C and Java (even easier) one have it. Why reinvent the wheel? I think it would be much easier for the developers to allow access to a C or Java routine from Basic.

Well, I'm not a developer. It's just an idea.


Code: (Select All)
//Beispiel aus: https://www.proggen.org/doku.php?id=c:lib:string:strtok
//Zeichenkette zerlegen in ihre einzelnen Wörter - 30. Mai 2023

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100

int main(void)
{
  char zk[] = "They never came back!";
    char zk2[MAX];
  char gesuchtes_zeichen[] = " "; 
  char *teil_wort;
    int wort = 1;
    
    //Zeichenkette in eine andere kopieren
    //funktioniert nur so.
    strcpy(zk2, zk);
    printf ("Zerlege Text: %s\n", zk );
  teil_wort = strtok(zk, gesuchtes_zeichen);
  while(teil_wort)
  {
    printf("Wort%2d: %s\n", wort++, teil_wort);
    teil_wort = strtok(NULL, gesuchtes_zeichen);
  }
  printf("\nAusgabe aufgeteilter Text: %s\n", zk2);
    
  return(0);
}

[Image: ZK-zerlegen-Token.jpg]
Reply


Messages In This Thread
String Tokenizer - by a740g - 05-25-2023, 03:33 PM
RE: String Tokenizer - by RhoSigma - 05-25-2023, 09:33 PM
RE: String Tokenizer - by a740g - 05-25-2023, 10:45 PM
RE: String Tokenizer - by Kernelpanic - 05-25-2023, 11:04 PM
RE: String Tokenizer - by a740g - 05-26-2023, 12:21 AM
RE: String Tokenizer - by Ultraman - 05-26-2023, 03:56 PM
RE: String Tokenizer - by Kernelpanic - 05-26-2023, 08:44 PM
RE: String Tokenizer - by Kernelpanic - 05-30-2023, 09:15 PM
RE: String Tokenizer - by Ultraman - 06-29-2023, 11:42 AM



Users browsing this thread: 7 Guest(s)