digitalmars.D.learn - How to use strip or stripRight on char[len] ? Thanks.
- FrankLike (12/12) Feb 22 2018 Hi,everyone,
- Adam D. Ruppe (8/10) Feb 22 2018 try:
- FrankLike (6/9) Feb 22 2018 char[100] abc ="aabc ";
- FrankLike (6/11) Feb 22 2018 char[100] abc ="aabc ";
- FrankLike (9/14) Feb 22 2018 Now,I want to get the result:
- Adam D. Ruppe (8/9) Feb 22 2018 You don't strip that at all, the function writes a
- FrankLike (3/5) Feb 22 2018 Thank you very much ! I forgot it.
Hi,everyone, How to use strip or stripRight on char[len]? For example: string abcs ="aabc "; auto abcsaa = abcs.stripRight; writeln(abcsaa); writeln("---abcsaa--stripRight ok---- "); char[100] abc ="aabc "; auto abcaa = ((abc).dup).stripRight; writeln(abcaa); writeln("----stripRight error----- "); Where is error? Thanks.
Feb 22 2018
On Thursday, 22 February 2018 at 16:55:14 UTC, FrankLike wrote:char[100] abc ="aabc "; auto abcaa = ((abc).dup).stripRight;try: auto abcaa = stripRight(abc[]) just make sure you do NOT return that abcaa from the function or store it in an object. It still refers to the static array that does not outlive that function. It is simply that these functions require a slice so it can resize it and you can't resize a static array.
Feb 22 2018
On Thursday, 22 February 2018 at 16:59:40 UTC, Adam D. Ruppe wrote:On Thursday, 22 February 2018 at 16:55:14 UTC, FrankLike wrote:It is simply that these functions require a slice so it can resize it and you can't resize a static array.char[100] abc ="aabc "; string aa = to!string(abc); string aaa = aa.stripRight; It get the same result.
Feb 22 2018
On Thursday, 22 February 2018 at 17:08:14 UTC, FrankLike wrote:On Thursday, 22 February 2018 at 16:59:40 UTC, Adam D. Ruppe wrote:char[100] abc ="aabc "; char[] p = abc; string aa = to!string(p); string aaa = aa.stripRight; It get the same result too.On Thursday, 22 February 2018 at 16:55:14 UTC, FrankLike wrote:It is simply that these functions require a slice so it can resize it and you can't resize a static array.
Feb 22 2018
On Thursday, 22 February 2018 at 16:59:40 UTC, Adam D. Ruppe wrote:On Thursday, 22 February 2018 at 16:55:14 UTC, FrankLike wrote:Now,I want to get the result: char[100] Path; writeln("will get path "); SHGetSpecialFolderPath(NULL,cast(char*)Path.ptr,CSIDL_DESKTOP,0); if use char[] Path; It not get the result. How to strip the Path? Thanks.char[100] abc ="aabc "; auto abcaa = ((abc).dup).stripRight;try: auto abcaa = stripRight(abc[])
Feb 22 2018
On Thursday, 22 February 2018 at 17:44:53 UTC, FrankLike wrote:SHGetSpecialFolderPath(NULL,cast(char*)Path.ptr,CSIDL_DESKTOP,0);You don't strip that at all, the function writes a zero-terminated string to the buffer. So either: use the pointer as-is to other C functions, or call the `fromStringz` function in Phobos to convert it and copy it if you want to store it. http://dpldocs.info/experimental-docs/std.string.fromStringz.html import std.string; string s = fromStringz(abc.ptr).idup; // the idup copies it out
Feb 22 2018
On Thursday, 22 February 2018 at 18:02:11 UTC, Adam D. Ruppe wrote:You don't strip that at all, the function writes a zero-terminated string to the buffer.Thank you very much ! I forgot it.
Feb 22 2018