字符串拆分 [英] string splitting

查看:79
本文介绍了字符串拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个程序:


char * strplit(char * str1,char * str2,char * stroriginal,int

split_point)


采用stroriginal并将

字符串的split_point元素拆分为另外两个字符串,

$ b $例如:


Hello World

i希望将此字符串拆分为Hello 世界


提前感谢,

andrea

解决方案

Andrea说:


我想写一个程序:


char * strplit(char * str1 ,char * str2,char * stroriginal,int

split_point)


采用stroriginal并拆分
$ b $的split_point元素b将字符串串成另外两个字符串,


例如:


Hello World

i想要将此字符串拆分为Hello "世界"



什么阻止你?你有什么尝试? (和谁一起负责存储分配

- 来电者还是分配者?)


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。


Richard Heathfield写道:


Andrea说:


>我想写一个程序:

char * strplit(char * str1,char * str2,char * stroriginal,int
split_point)

采取stroriginal并将
字符串的split_point元素拆分为另外两个字符串,

例如:

Hello World
我想把这个字符串分成你好。 "世界"



什么阻止你?



不合适的原型?

char * strplit(char * str1,char * str2,char * stroriginal,

int split_point)


OP的问题:

str1,str2,stroriginal和

split_point应该传递什么?返回

值的重要意义是什么?


如我所写,我怀疑你打算把这两个分元 -

字符串进入str1和str2指向的内存,

你的函数将如何知道对象指向

这些是否足以容纳子字符串?


-

imalone




Andrea写道:


我想编写一个程序:


char * strplit(char * str1,char * str2,char * stroriginal,int

split_point)


采取stroriginal并拆分在

字符串的split_point元素中将字符串分成两部分其他字符串,


例如:


Hello World

i希望将此字符串拆分为你好 "世界"



请发布您的尝试。此外,返回值

指向什么?因为你的函数不需要修改它,所以const也可以更好地将指针限定为

原始字符串。你还需要

来决定是否应该在调用者或被调用者中完成str1和str2的内存分配




I want to write a program that:

char * strplit(char* str1, char *str2, char * stroriginal,int
split_point)

that take stroriginal and split in the split_point element of the
string the string into two other strings,

example:

"Hello World"
i want to split this string into "Hello " "World"

thanks in advance,
andrea

解决方案

Andrea said:

I want to write a program that:

char * strplit(char* str1, char *str2, char * stroriginal,int
split_point)

that take stroriginal and split in the split_point element of the
string the string into two other strings,

example:

"Hello World"
i want to split this string into "Hello " "World"

What''s stopping you? What have you tried? (And with whom lies the
responsibility for storage allocation - the caller or the splitter?)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Richard Heathfield wrote:

Andrea said:

>I want to write a program that:

char * strplit(char* str1, char *str2, char * stroriginal,int
split_point)

that take stroriginal and split in the split_point element of the
string the string into two other strings,

example:

"Hello World"
i want to split this string into "Hello " "World"


What''s stopping you?

An inappropriate prototype?
char * strplit(char* str1, char *str2, char * stroriginal,
int split_point)

Questions for the OP:
What should be passed in str1, str2, stroriginal and
split_point? What is the significance of the return
value going to be?

As written I suspect that you plan to put the two sub-
strings into the memory pointed to by str1 and str2,
how will your function know that the objects pointed
to by these are large enough to hold the sub-strings?

--
imalone



Andrea wrote:

I want to write a program that:

char * strplit(char* str1, char *str2, char * stroriginal,int
split_point)

that take stroriginal and split in the split_point element of the
string the string into two other strings,

example:

"Hello World"
i want to split this string into "Hello " "World"

Please post your attempt. Additionally what does the return value
point to? It''s also perhaps better to const qualify the pointer to the
original string since your function need not modify it. You also need
to decide whether memory allocation for str1 and str2 should be done
in the caller or in the callee.


这篇关于字符串拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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