- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试阅读一些长度不超过 100 个字符的文本,然后去掉其中的空格、数字、特殊字符等。我正在考虑如何进行此操作,但我想我一定忘记了我所知道的关于 cstrings 等的大部分内容。我最初只是想接受基本字符并将它们复制到一个新字符串中,但是 1。我不知道如何编写它,所以我的编译器不讨厌我和 2。我很确定我不希望新的、剥离的字符串中有空格(我很确定我的代码到目前为止会导致这种情况发生,如果它能工作的话)。
char * userText="";
char * justCharTxt;
cout << "Enter text: " << endl;
cin.getline(userText, STRING_SIZE);
for (int i = 0; i < strlen(userText); i++){
if (((userText[i] >= 'a') && (userText[i] <= 'z')) ||
((userText[i] >= 'A') && (userText[i] <= 'Z')))
*justCharTxt = userTxt[i];
}
关于这个问题的一些指导会很棒。谢谢!
最佳答案
只需使用 std::string
,无需摆弄 char
数组或指针。
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string line;
getline(std::cin, line);
line.erase(
std::remove_if(line.begin(), line.end(),
[](char c) {return !isalpha(c, std::locale());}),
line.end()
);
std::cout << line << '\n';
}
关于c++ - 删除/忽略 Cstring 中除字符以外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23257947/
给定 CString buffer = ""; Cstring value = "blah"; buffer.Format ("%s %s", value, value.GetBuffer()); 这
我有这个函数可以将事件(每个事件都是一个 cstring)添加到事件数组中: bool vendor::addEvent(const char * event) { if (eventsSiz
我可以在 CString::Format 中使用 CString 吗,如下所示: CString text = _T("text"); CString format; format.Format(_T
我正在 Ubuntu 16.04 上使用 ROS 和 C++ 开展一个小组项目。一切正常,直到两周前我收到此错误突然的消息: In file included from /usr/include/c+
我有一个将 CString 作为参数之一的函数,我查看了代码库,发现很多地方都使用 const CString& 作为参数。 所以我想知道使用 CString 与 const CString& 之间是
我有两个列表和一个名字要查找。如果要查找的名称不在第一个列表中,那么它可能在格式略有不同的第二个列表中。给出了两种格式之间的转换函数。 std::map* convertedNames; BOOL C
我需要为我的对象计算签名(一种哈希)。计算需要许多每个字符的操作,因此为了加快此过程,我的代码对 CString 进行操作,然后将计算的 CString 转换为最终的 NSString。 stub 代
PVS 工作室发现了一个我正在调查的潜在缺陷;警告 V623 http://www.viva64.com/en/d/0240/ 但是,没有足够的解释来理解为什么要制作临时拷贝。如果 CString::
假设我有以下字符串 char array[1000]; 我如何将它转换为 NSString,反之亦然。 谢谢。 最佳答案 Apple 的开发者引用有一个 good article关于这个问题。基本上,
一些简单的代码在我一直使用的 sdk 中开始出现故障,而且它显然已经正常工作了很长时间,事实上我几乎可以肯定我已经编译了部分代码并且他们有工作,但最近失败了。 在调试器中确认值的示例: void So
我正在尝试这样做: #include CHAR Filename; // [sp+26Ch] [bp-110h]@1 char v31; // [sp+36Ch] [bp-10h]@1 int v3
我知道字符数组不同于 cstring,因为在 cstring 中包含后缀\0 标记值。然而,我也明白,在 cstring、字符数组或任何其他类型的数组的情况下,程序中的数组标识符是指向数组的指针。所以
我在将 unsigned char 转换为 CString 以及将转换后的 CString 结果转换为 unsigned char 时遇到问题。 首先,我尝试使用 CString.append();。
我正在使用一个 Windows 应用程序来解析某些二进制文件。应用程序每次在某个位置都会崩溃(读取访问冲突)。 我正在尝试找出崩溃的根本原因。 (f74.fac): Access violation
需要使用下面的 LogMethod() 来记录 buf 的内容问题是LogMethos 只接受“Const CString&” char buf[1024]; strcpy(buf, cErrorMs
假设我有一个文件。我将所有字节读入一个无符号字符缓冲区。从那里我试图在不知道它的长度的情况下读取一个 c 字符串(空终止)。 我尝试了以下方法: char* Stream::ReadCString()
我在使用数组时遇到问题。我收到以下错误 In function ‘int main(int, const char**)’: 75: error: cannot convert ‘char*’ to
我一直在尝试执行从包含十六进制字符串的 CString 到字节数组的转换,并且一直在 至今未成功。我查看了论坛,到目前为止似乎都没有帮助。有没有一个功能只有几个 执行此转换的代码行数? 我的代码: B
我有两个 CString s1 和 CString s2。我需要在 s1 中找到最后一个条目 s2。我可以在 CString 中找到任何方法,就像在 C# LastIndexOf 中一样。我在 C++
我想将丰富的编辑控件中的整个文本作为 CString 获取,例如 GetDlgItemText,但这是针对对话框的。我能从我的研究中找到的最接近的东西是: GetTextRange并使用 GetTex
我是一名优秀的程序员,十分优秀!