查找符合条件的字符? [英] Find characters in line?

查看:82
本文介绍了查找符合条件的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条类似"kjhdjhdah @ lddhfdj"的行.您能给我伪代码在行中找到@符号吗?

I had a line like "kjhdjhdah@lddhfdj".Can you please give me pseudo code to find @ symbol in the line?

推荐答案

开始此处 [此处 [ ^ ]并花费有一段时间学习.如果您想了解如何操作字符串中的字符,请在库部分中找到std :: string的条目,并检查所有可用的方法;否则,请参见.可能会有一个叫做 find() [
Start here[^] and here[^] and spend some time studying. If you want to find out how to manipulate characters within strings then find the entry for std::string in the library section and check all the available methods; there will probably be one called find()[^]. You should really get familiar with the MSDN documentation, as I have suggested to you in a number of your previous questions.


使用strchr()函数.

Use strchr() function.

char *strchr(
   const char *string,
   int c 
);
);



返回指向字符串中第一次出现c的指针;如果找不到c,则返回NULL. 对于Unicode版本,可以使用wcschr.



Returns a pointer to the first occurrence of c in string, or NULL if c is not found.
For Unicode version, wcschr can be used.


使用
char * strchr ( const char *, int ); 


考虑下面的示例.


consider the example below.

/* strchr example */
#include <stdio.h>
#include <string.h>

int main ()
{
    char str[] = "This is a sample string";
    char * pch;
    printf ( "Looking for the 's'character in \"%s\"...\n", str );
    pch = strchr(str,'s' );
    while ( pch != NULL )
    {
        printf ( "found at %d\n", pch - str + 1 );
        pch = strchr( pch + 1, 's' );
    }
   return 0;
}</string.h></stdio.h>


这篇关于查找符合条件的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆