www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - String Basics

reply Heinz <Heinz_member pathlink.com> writes:
Hi, it's a kind of silly question: How can i use a string as a type? for example
i want to pass a parameter as a string but the compiler says string is not
defined, which module dhould i import to work with strings?

thx.
Jun 23 2006
next sibling parent Frank Benoit <keinfarbton nospam.xyz> writes:
In D there is no "string". Instead there is char[] (, dchar[] or wchar[]).

There are some utility functions in std.string, but for making use of
char[] you need nothing to be imported.
Jun 23 2006
prev sibling next sibling parent reply Yossarian <phoenix flareware.cz> writes:
Heinz napsal(a):
 Hi, it's a kind of silly question: How can i use a string as a type? for
example
 i want to pass a parameter as a string but the compiler says string is not
 defined, which module dhould i import to work with strings?
 
 thx.
 
 
try to write somewhere in declaration part: alias char[] string; or use char[] as string:)
Jun 24 2006
parent David Medlock <noone nowhere.com> writes:
Yossarian wrote:

 Heinz napsal(a):
 
 Hi, it's a kind of silly question: How can i use a string as a type? 
 for example
 i want to pass a parameter as a string but the compiler says string is 
 not
 defined, which module dhould i import to work with strings?

 thx.
try to write somewhere in declaration part: alias char[] string;
or get Walter to put this in phobos! :D -DavidM
Jun 24 2006
prev sibling parent reply Heinz <Heinz_member pathlink.com> writes:
In article <e7imaq$2jql$1 digitaldaemon.com>, Heinz says...
Hi, it's a kind of silly question: How can i use a string as a type? for example
i want to pass a parameter as a string but the compiler says string is not
defined, which module dhould i import to work with strings?

thx.
Thanks guys for your answers. I know it is a basic stuff, i used to work with char[] in lower level languages but now i was used to the string type in managed languages. I'll use an alias for now but hope Walter to add a string type in phobos.
Jun 24 2006
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Heinz" <Heinz_member pathlink.com> wrote in message 
news:e7jj7v$sdo$1 digitaldaemon.com...

 Thanks guys for your answers. I know it is a basic stuff, i used to work 
 with
 char[] in lower level languages but now i was used to the string type in 
 managed
 languages.
D is "managed" ;) That's just MS's fancy term for "Garbage Collected."
 I'll use an alias for now but hope Walter to add a string type in phobos.
You'd be surprised, but char[] handles just about any kind of string handling. I've never felt like I was lacking an explicit string type in D.
Jun 24 2006
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:e7kplh$2h7u$1 digitaldaemon.com...

 That's just MS's fancy term for "Garbage Collected."
Though it might mean more. I've only ever heard it in the context of being "garbage collected."
Jun 24 2006
prev sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Jarrett Billingsley wrote:

 D is "managed" ;)  That's just MS's fancy term for "Garbage Collected."
Managed means virtual machine. http://en.wikipedia.org/wiki/Managed_code The usual / native code is now (belittlingly) known as Unmanaged code... --anders
Jun 25 2006
parent reply "Andrei Khropov" <andkhropov nospam_mtu-net.ru> writes:
Anders F Björklund wrote:


Well, what about D++ then? <g>
Jun 25 2006
parent James Pelcis <jpelcis gmail.com> writes:
Andrei Khropov wrote:
 Anders F Björklund wrote:
 

Well, what about D++ then? <g>
That's already taken. http://www.pagemac.com/dpp/
Jun 25 2006
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Heinz wrote:
<snip>
 Thanks guys for your answers. I know it is a basic stuff, i used to work with
 char[] in lower level languages but now i was used to the string type in
managed
 languages.
 
 I'll use an alias for now but hope Walter to add a string type in phobos.
http://www.digitalmars.com/d/builtin.html "But after all, what is a string if not an array of characters? If the builtin array problems are fixed, doesn't that resolve the string problems as well? It does. It seems odd at first that D doesn't have a string class, but since manipulating strings is nothing more than manipulating arrays of characters, if arrays work, there's nothing a class adds to it." Stewart.
Jun 26 2006
parent reply Kent Boogaart <Kent_member pathlink.com> writes:
I'm a late entrant on this discussion, but I've only just gotten on the D band
wagon . . .

I think adding a string type has some serious merit. Namely:

1. "string" is a lot easier on the eyes than "char[]", to me at least.
Especially when being used in an associative array:

int[char[]] arr;

versus

int[string] arr;

2. string-specific functions can be added to the string type. I'm a complete D
noob so forgive any misinformation here. Currently I understand there to be a
separate module for string-related functions. To me, there should be a string
type that defines those functions:

char[] upper = toupper(myString);

versus:

string upper = myString.toupper();

The latter seems like much better OO design to me. Side note: I don't understand
the namng of "toupper" as opposed to "toUpper" - isn't camel-casing the norm in
D?

Now arguably developers could just typedef or alias char[] as string and be done
with it. But this doesn't address my second point.

Or they could develop their own string class and be done with it. But this means
that almost every decent-sized D project will have its own string
implementation. Obviously not good.

Regards,
Kent Boogaart


In article <e7oki3$2pfe$1 digitaldaemon.com>, Stewart Gordon says...
Heinz wrote:
<snip>
 Thanks guys for your answers. I know it is a basic stuff, i used to work with
 char[] in lower level languages but now i was used to the string type in
managed
 languages.
 
 I'll use an alias for now but hope Walter to add a string type in phobos.
http://www.digitalmars.com/d/builtin.html "But after all, what is a string if not an array of characters? If the builtin array problems are fixed, doesn't that resolve the string problems as well? It does. It seems odd at first that D doesn't have a string class, but since manipulating strings is nothing more than manipulating arrays of characters, if arrays work, there's nothing a class adds to it." Stewart.
Jul 22 2006
next sibling parent Mike Parker <aldacron71 yahoo.com> writes:
Kent Boogaart wrote:

 2. string-specific functions can be added to the string type. I'm a complete D
 noob so forgive any misinformation here. Currently I understand there to be a
 separate module for string-related functions. To me, there should be a string
 type that defines those functions:
 
 char[] upper = toupper(myString);
 
 versus:
 
 string upper = myString.toupper();
You can do that now: char[] myString = "myString"; cahr[] upper = myString.toupper();
 
 The latter seems like much better OO design to me. 
Don't forget that D supports the procedural programming paradigm as well. Object Orientation has benefits, but is not a panacea. In my opinion, it shouldn't matter whether or not standard library APIs use OO design priniciples, as it generally does not affect the design of user code. Besides which, OO does not necessarily mean 'classes'. There are plenty of free function APIs that follow the OO paradigm. OpenGL is a great example. IMO, the need for a string class in D is imaginary. I have no use for one.
Jul 22 2006
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Kent Boogaart wrote:
<snip>
 Or they could develop their own string class and be done with it. But this
means
 that almost every decent-sized D project will have its own string
 implementation. Obviously not good.
<snip top of upside-down reply> Only if nearly every D programmer is an OO purist. http://www.digitalmars.com/d/overview.html "Who D is Not For" "Language purists. D is a practical language, and each feature of it is evaluated in that light, rather than by an ideal. For example, D has constructs and semantics that virtually eliminate the need for pointers for ordinary tasks. But pointers are still there, because sometimes the rules need to be broken. Similarly, casts are still there for those times when the typing system needs to be overridden." Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 23 2006