如何从字符串中删除空格和特殊字符?
谷歌搜索时我找不到一个答案.有很多与其他语言有关,但不是C.大多数人都提到使用正则表达式,这不是C标准(?).
删除简单空间很容易:
char str[50] = "Remove The Spaces!!";
Run Code Online (Sandbox Code Playgroud)
然后是一个带有if语句的简单循环:
if (str[i] != ' ');
Run Code Online (Sandbox Code Playgroud)
输出将是:
RemoveTheSpaces!!
Run Code Online (Sandbox Code Playgroud)
我将什么添加到if语句中以便识别特殊字符并将其删除?
我对特殊字符的定义:
Characters not included in this list:
A-Z a-z 0-9
Run Code Online (Sandbox Code Playgroud) 我开始学习C#,我的一个任务遇到了问题.任务是创建一个由星星组成的金字塔.高度由用户输入指定.
由于某种原因,我的第一个for循环跳到最后.在调试时,我注意到变量height接收bar到了值,但之后它跳到了最后.我不知道为什么,因为代码对我来说似乎很好.
本do- while循环是有要求用户输入一个新值,如果输入的值0或更低.
using System;
namespace Viope
{
class Vioppe
{
static void Main()
{
int bar;
do
{
Console.Write("Anna korkeus: ");
string foo = Console.ReadLine();
bar = int.Parse(foo);
}
while (bar <= 0);
for (int height = bar; height == 0; height--)
{
for (int spaces = height; spaces == height - 1; spaces--)
{
Console.Write(" ");
}
for (int stars = 1; stars >= height; stars …Run Code Online (Sandbox Code Playgroud)