除去文本文件每一行的空格&&提取每一行第一个和最后一个字符串
来源:互联网 发布:银行用户画像 大数据 编辑:程序博客网 时间:2024/05/16 09:49
除去文本文件每一行的空格
python:
files="conky.conf"fin =open(files)fout=open(files+'1','w')for line in fin: print (line) fout.write(line.strip()+'\n')
cpp:
#include <ctype.h> #include<iostream> #include<fstream> #include<string.h> #define bufsize 300 using namespace std; int main() { char buf[bufsize]; ifstream ifs("vimrc.txt",ifstream::in); ofstream ofs("vimrc-.txt",ofstream::out); if (ifs.is_open()) cout<<"open file successful"<<endl; else{ cout<<"open file fail"<<endl; return 1; } char *p=NULL; int flag; cout<<"if input 0, only remove space back of line. else remove front and back of line. "<<endl; cin>>flag; while(ifs.getline(buf,bufsize)) { int len =strlen(buf); while(isspace(buf[len-1])) len--; buf[len]='\0'; if(flag!=0) { len=0; while(isspace(buf[len])) len++; p=buf+len; cout<< p <<endl; ofs<< p <<endl; } else { cout<<buf<<","<<strlen(buf)<<endl; ofs<<buf<<endl; } } ofs.close(); ifs.close(); return 0; }
提取每一行第一个和最后一个字符串
/************************************************************************* > File Name: str.cpp > Author: ims > Created Time: 2017/10/26 18:12:14 ************************************************************************/#include<iostream>#include<fstream>using namespace std;int main(){ifstream ifs("3ss.txt",ifstream::in); char *p, first[100],buf[200]; int len=0; while(ifs.getline(buf,200)) { int tem=0; len=strlen(buf); while(isspace(buf[tem])&&tem<len) tem++; if(tem==len) continue; else p=&buf[tem]; while(!isspace(buf[tem])&&tem<len) tem++; strcpy(first,p); first[tem]='\0'; if(tem==len) { cout<<"1:only one str:"<<first<<endl; continue; } while(isspace(buf[tem])&&tem<len) tem++; if(tem<len) { tem=len; cout<< "src:"<<buf<<",len:"<< len <<endl; while(isspace(buf[tem-1])) tem--; buf[tem]='\0'; while(!isspace(buf[tem-1])) tem--; p=&buf[tem]; cout<<"first str:"<< first <<endl; cout<<"last str:"<<p<<endl; } else cout<<"2:only one str:"<<first<<endl; }return 0;}
阅读全文
0 0
- 除去文本文件每一行的空格&&提取每一行第一个和最后一个字符串
- 读文本文件的每一行 取每行最后一个空格后的子串
- 去掉txt文件中每一行字符串内容的第一个空格
- Java统计一个文本文件中每一行字符串出现的次数
- Linux下错误:文本文件每一行最后多了 ^M
- fileread函数:IDL中将文本文件读入一个字符串数组中,每一行作为一个元素
- 批处理提取文本文件第一行跟最后一行的方法
- 给文本文件的每一行按顺序标号
- 用cmd在一个文本文件中的每一行后添加相同的字符
- 关于php文件查找每一行的字符串与指定文件中的每一行的字符串
- 给定一个整数,分别打印出每一位数字,然后每行都省略输出上一行的第一个数字
- 读取一个文本文件的最后一行
- 正则表达式获取一个文本域中每一行的值并且去掉前后空格
- 显示每一行的序号
- 数据库每一行的长度
- 给定一个文件每一行是字符串,找出所有的逆序对,比如abc和cba是逆序的对。
- 给定一个文件每一行是字符串,找出所有的逆序对,比如abc和cba是逆序的对。
- 去掉字符串第一个非空格字母 和最后一个非空格字母两端的空格
- java中hashmap的作用
- php 解决json_encode中文UNICODE转码问题
- ARM软件访问硬件的核心理论
- MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
- 思维导图的制作
- 除去文本文件每一行的空格&&提取每一行第一个和最后一个字符串
- ALLEGRO封装文件格式简介
- AngularJs调用路由
- 破解百度网盘限速,告别下载速度慢
- 第二章 感知机_李航
- Python-jieba分词
- 终于搞懂令人迷惑的 StatusBar 了
- 使用svctraceviewer查看WCF服务异常信息
- MyBatis学习总结(五)——实现关联表查询