· Начало · Отвђтить · Статистика · Поиск · FAQ · Правила · Установки · Язык · Выход · WASM.RU · Noir.Ru ·

 WASM Phorum —› WASM.WIN32 —› Разбиение строки по формату

Посл.отвђт Сообщенiе


Дата: Мар 27, 2004 00:55:13

Есть ли какие либо специализированные функции разбиения строк. Тоесть обратная функция wsprintf.
Строка: /show me:10 ( /%s %s:%s )
И в результате надо получить:
buf1="show"
buf2="me"
buf3="10"


Дата: Мар 27, 2004 00:58:20

strtok


Дата: Мар 27, 2004 01:26:13

Вобщем понял, но не совсем.
invoke strtok,addr string1,addr string2
.while (eax)
 invoke strtok,NULL,addr string2
.endw

Это я типа по Сишному коду нацарапал. 8)
Если я не прав то допоможите мне.


Дата: Мар 27, 2004 03:50:16

Не прав. strtok вызывается два раза.
Пример, кстати, взят из MSDN, который, между прочим, иногда надо читать!
#include <string.h>
#include <stdio.h>

char string[] = "A string\tof ,,tokens\nand some  more tokens";
char seps[]   = " ,\t\n";
char *token;

void main( void )
{
   printf( "%s\n\nTokens:\n", string );
   /* Establish string and get the first token: */
   token = strtok( string, seps );
   while( token )
   {
      /* While there are tokens in "string" */
      printf( " %s\n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}


Дата: Мар 27, 2004 06:26:19

Можно ещё с помощью sscanf. Но в отличии от wsprintf аналога этой функции в Win API нет. Вот что по этому поводу говорит MSDN:

sscanf, swscanf
Read formatted data from a string.

int sscanf( const char *buffer, const char *format [, argument ] ... );

int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );

Routine Required Header Compatibility
sscanf <stdio.h> ANSI, Win 95, Win NT
swscanf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT


Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end of the string is reached before the first conversion.

Parameters

buffer - Stored data
format - Format-control string
argument - Optional arguments

For more information, see Format Specifications.

Remarks

The sscanf function reads data from buffer into the location given by each argument. Every argument must be a pointer to a variable with a type that corresponds to a type specifier in format. The format argument controls the interpretation of the input fields and has the same form and function as the format argument for the scanf function; see scanf for a complete description of format. If copying takes place between strings that overlap, the behavior is undefined.

swscanf is a wide-character version of sscanf; the arguments to swscanf are wide-character strings. sscanf does not handle multibyte hexadecimal characters. swscanf does not handle Unicode fullwidth hexadecimal or “compatibility zone” characters. Otherwise, swscanf and sscanf behave identically.

Example

/* SSCANF.C: This program uses sscanf to read data items
* from a string named tokenstring, then displays them.
*/

#include <stdio.h>

void main( void )
{
char tokenstring[] = "15 12 14...";
char s[81];
char c;
int i;
float fp;

/* Input various data from tokenstring: */
sscanf( tokenstring, "%s", s );
sscanf( tokenstring, "%c", &c );
sscanf( tokenstring, "%d", &i );
sscanf( tokenstring, "%f", &fp );

/* Output the data read */
printf( "String = %s\n", s );
printf( "Character = %c\n", c );
printf( "Integer: = %d\n", i );
printf( "Real: = %f\n", fp );
}


Output

String = 15
Character = 1
Integer: = 15
Real: = 15.000000


Дата: Мар 29, 2004 01:26:10

А как все это реализовать на асме?
Может проще побайтно сканировать строку?


Дата: Мар 29, 2004 02:54:16

offtop: вот тут бы perl бы и пригодился


Дата: Мар 29, 2004 12:13:48

Конечно, если нужна незнайкакая скорость - стОит написать своё. А так, все необходимые функции лежат в MSVCRT.DLL. Зачем изобретать велосипед?


Powered by miniBB 1.6 © 2001-2002
Время загрузки страницы (сек.): 0.077