如何使用宽字符到multibytes字符串的字符之间移除空间? [英] how to remove space between characters of a string using wide char to multibytes?

查看:181
本文介绍了如何使用宽字符到multibytes字符串的字符之间移除空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WINHEX样子后续打开的文件。

I have a file open in winhex look like follow.

00 1F 48 3A 18 00 00 00 53 00 70 00 00 6F 75 00
73 00 65 00 00 5楼61 00 00 7A 61 00 6D 00 00 00

1F 00 48 3A 18 00 00 00 53 00 70 00 6F 00 75 00 73 00 65 00 5F 00 61 00 7A 00 61 00 6D 00 00 00

我从文件中读取上面的十六进制数据,并将其写入到一个文本文件中。我的code是如下。

I am reading the above hex data from file and write it to a text file . My code is as follow.

#include<stdlib.h>
#include<stdio.h>
#include<iostream.h>
int main()
{
FILE *pFile, *tempFile;
char *Main_buffer;
int nOfRecord, TotalSize, data=0;
pFile = fopen("C:\\wab files\\Main.wab", "rb"); 
if(pFile == NULL)
{
    fputs("file error", stderr);
    exit(1);
}
tempFile = fopen("C:\\myfile.text","wb");
if(tempFile == NULL)
{
    fputs("file not open", stderr);
    exit(2);
}
 fread(&nOfRecord, 1, 4, pFile);
 fread(&TotalSize, 1, 4, pFile);
 data = TotalSize;
 char* Main_buffer = (char*)malloc(data*sizeof(data));
 fread(Main_buffer, 1, TotalSize, pFile);
 fwrite(Main_buffer, 1, TotalSize, tempFile);
 free(Main_buffer);
 return 0;
}

此code给出,其中数据被写入如下文本文件。

This code gives a text file in which data is written as follow.

P A l在克间一I L。 C 0

p a l @ g m a i l . c o

在上面的数据有各字符之间的空间。如何从数据中移除的空间,并且在文本文件中写入。通过编写一些code为宽字符多字节的例子请解释。感谢您提前。

In above data there is a space between each character . How to remove space from the data, and write in a text file . Please explain by writing some code as an example for wide char to multi bytes . Thanks you in advance .

推荐答案

有基本上做这件事的2种方式:

There are basically 2 ways of doing it:


  1. 手动从生成ASCII东西去掉空格。

  1. Manually removing spaces from the generated ASCII thing.

使用库做的工作适合你(当然,如果你被允许)。我的preference去朝
http://en.wikipedia.org/wiki/Iconv

Use a library to do the work for you (of course if you are allowed to). My preference goes toward http://en.wikipedia.org/wiki/Iconv

这(如维基百科页面上说的)在海湾合作委员会自由的实现,所以你可以尝试用它来播放。
而这里的链接到Linux lib目录下:
http://www.gnu.org/software/libiconv/#TOCintroduction

which (as said on the Wikipedia page) has a free implementation in GCC so you can try to play with it. And here the link to the Linux lib: http://www.gnu.org/software/libiconv/#TOCintroduction

更新

下面是如何使用libiconv的℃的例子:
http://www.gnu.org/software/libc/manual /html_node/iconv-Examples.html

Here is an example in C of how to use libiconv: http://www.gnu.org/software/libc/manual/html_node/iconv-Examples.html

这篇关于如何使用宽字符到multibytes字符串的字符之间移除空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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