2.33模型--去除字符串两头空格.c
【注:本程序验证是使用vs2013版】
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996) int my_strRidSpace(char *dest,char *src, int *n){
char *buf = src;
int begin = ;
int end = strlen(buf) - ;
int len = ; if (buf == NULL || dest==NULL){ return -; }
//从左边开始
while (buf[begin] == ' ' && buf[begin] != ){ //如果当前字符不为空,而且没有结束
begin++;//位置 右移动一位
}
while (buf[end] == ' ' && buf[end] != ){ //如果当前字符不为空,而且没有结束
end--;//位置 左移动一位
}
len = end - begin + ;
*n = len;
strncpy(dest, buf + begin, len);//strncpy():拷贝字符串到dest,指定长度(后边不添加0)
dest[len] = ;
/*这里是自己实现的指定长度拷贝字符串函数
for (int i = 0; i < len; i++){
*dest = *(buf + begin);
dest++;
buf++;
}
*/ return ;
} int main(void){
/* 查找非空格字符串个长度,两头堵模型 例子:" asfqwfq " */
char *p = " asdqwfrd ";
char str[] = { };
int n = ;
int ret = ; ret = my_strRidSpace(str,p, &n);
if (ret != ){
printf("my_strRidSpace err %d", ret);
return ret;
}
printf("str = %s\n", str);
printf("n= %d\n", n);
printf("\n");
system("pause");
return ;
}
2.33模型--去除字符串两头空格.c的更多相关文章
- trim()方法去除字符串首尾空格
trim()方法去除字符串首尾空格 1.原生js Function trimStr(str){ Return str.r ...
- 正则表达式去除字符串左右空格函数 调用方法是,str.Trim();
正则表达式去除字符串左右空格函数 调用方法是,str.Trim(); String.prototype.Trim = function() { return this.replace(/(^\s*)| ...
- [py]str list切片-去除字符串首尾空格-递归思想
取出arr的前几项 #方法1 print([arr[0], arr[1]]) #方法2 arr2 = [] for i in range(2): arr2.append(arr[i]) print(a ...
- SQL TRIM()函数去除字符串头尾空格
SQL TRIM()函数去除字符串头尾空格 SQL 中的 TRIM 函数是用来移除掉一个字串中的字头或字尾.最常见的用途是移除字首或字尾的空白.这个函数在不同的资料库中有不同的名称: MySQL: T ...
- Python关于去除字符串中空格的方法
Python关于去除字符串中空格的方法 在编写程序时我们经常会遇到需要将字符串中的空格去掉的情况,通常我们可以使用下面几种解决方法: 1.strip()方法:该方法只能把字符串头和尾的空格去掉,但是不 ...
- Golang去除字符串前后空格
Golang去除字符串前后空格 实现Demo package main import "fmt" func DeletePreAndSufSpace(str string) str ...
- Java中去除字符串中空格的方法
昨天写了一个关于Excel文件处理的脚本,在字符串匹配功能上总是出现多余不正确的匹配,debug调试之后,发现一个坑. ------->代码中字符串使用了replaceAll()方法,去除了所有 ...
- JavaScript去除字符串两边空格trim
去除字符串左右两端的空格,在大部分编程语言中,比如PHP.vbscript里面可以轻松地使用 trim.ltrim 或 rtrim实现.但在js中却没有这3个内置方法,需要手工编写.下面的实现方法是用 ...
- 【iOS】去除字符串首尾空格或某字符
在iOS的实际开发中,常会出现需要去除空格的情况,总结有三种情况: 去除字符串首尾连续字符(如空格): 去除字符串首部连续字符(如空格): 去除字符串尾部连续字符(如空格): 去除字符串首尾连续字符( ...
随机推荐
- 查看 ssh 攻击 和 攻击成功者
查看攻击失败记录: grep "Failed password for invalid user admin" /var/log/auth.log 查看攻击成功的记录: grep ...
- arcpy 重分类
arcpy.gp.Reclassify_sa("dem.tif","Value","0 2000 1;2000 2100 2;2100 2500 3; ...
- Mono Features of cheat engine
If you attach to a process/game that uses mono, you should see a new "Mono" menu item on t ...
- JavaScript data types and data structures
JavaScript data types and data structures Programming languages all have built-in data structures, b ...
- maven项目新检出后不编译爬坑记 及 mvn clean package报错 WagonTransporterFactory: java.util.NoSuchElementException 异常【我】
从SVN新检出一个maven项目,配置好后,发现项目无法编译(只有一个test包中的代码显示编译报错,其他所有包中的代码都不编译,也不报错), 先注释掉报错的test包中的所有内容, 用Eclipse ...
- Oracle中RAISE异常
转: Oracle中RAISE异常 由三种方式抛出异常 1. 通过PL/SQL运行时引擎 2. 使用RAISE语句 3. 调用RAISE_APPLICATION_ERROR存储过程 当数据库或PL/S ...
- 【JAVA】java注解的自定义和使用
java注解概念 Java提供了一种原程序中的元素关联任何信息和任何数据的途径和方法 java注解介绍 常用注解 @Override:表示方法是重写的方法 @Deprecated:过时的方法 @Sup ...
- 【428】Dijkstra 算法
算法思想:(单源最短路径) 1个点到所有其他点的最短路径 查找顶点到其他顶点的最短路径,无法到达的记为+∞,找到最小的,就找到了最短路径的顶点 查看上一轮找到的最小点到达其他点的最小值,找到最短路径的 ...
- 123457123457#0#----com.MC.3or1KongLongPT867----前拼后广--3or1恐龙PtGame-mc
com.MC.3or1KongLongPT867----前拼后广--3or1恐龙PtGame-mc
- centos 7 修改计算机名
[root@centos7 ~]$ hostnamectl set-hostname test.xyz.com # 使用这个命令会立即生效且重启也生效 [root@centos7 ~]$ host ...
printf("\n");