Difference between revisions of "Manual:DIL Manual/string"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import of LLM wiki pages)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== String ==
 
A string is some text. They are used for a lot of things such as command
 
arguments, room descriptions etc. String variables are automatically resized and
 
allocated when you assign them, so you do not have to worry about the string
 
length nor allocation in your DIL programs. Strings may be compared either with
 
  
::'==' (equal to),
 
::'!=' (not equal),
 
::'<=' (less than or equal to),
 
::'>=' (greater than or equal to)
 
::'<' (less than),
 
::'>' (greater than.
 
  
Static strings are defined just as in the rest of the zone, within double
+
<span id="str"></span>
quotations. Strings may be searched easily with the 'in' operator.  Variables
+
  '''String:'''
of type string are saved with DIL programs, if attached to a saved unit.
 
  
=== Example ===
+
    A string is some text. They are used for a lot of things such as command
   "This is a static string"
+
arguments, room descriptions etc. String variables are automatically resized and
 +
allocated when you assign them, so you do not have to worry about the string
 +
length nor allocation in your DIL programs. Strings may be compared either with
 +
'==' (equal to),
 +
'!=' (not equal),
 +
'<=' (less than or equal to),
 +
'>=' (greater than or equal to)
 +
'<' (less than),
 +
   '>' (greater than.
  
Strings may also be added to each other, in an expression.
+
  Static strings are defined just as in the rest of the zone, within double
 +
quotations.  Strings may be searched easily with the 'in' operator.  Variables
 +
of type string are saved with DIL programs, if attached to a saved unit.
  
=== Example ===
+
'''Example:'''
  "say "+itoa(42)+" is the answer!"
 
  
=== Example ===
+
  "This is a static string"
  
  if (self.name == self.names.[1]) ...
+
Strings may also be added to each other, in an expression.
  
Elements of the string can also be accessed by referencing them by their position.
+
'''Example:'''
  
=== Example ===
+
  "say "+itoa(42)+" is the answer!"
  if (str.[3]=="f")
 
  {
 
    exec ("say The 4th element is a F.",self);
 
  }
 
  
=== Note ===
+
  '''Example:'''
Currently you can only access the single elements of a string you can not set
 
them. In the future this will be possible.  You can still accomplish this by
 
copying one string to the other one element at a time and changing any that you
 
want something like this.
 
  
=== Example ===
+
  if (self.name == self.names.[1]) ...
  i:=0;
+
 
  ln:=length (str);
+
  Elements of the string can also be accessed by referencing them by their position.
  while (str.[i]<ln)
+
 
  {
+
  '''Example'''
    if (str.[i]=="f")
+
  if (str.[3]==f])
      newstr.[i]:="b";
+
  {
    else
+
  exec ("say The 4th element is a F.",self);
      newstr:=str.[i];
 
    i := i + 1;
 
 
   }
 
   }
  str:=newstr;
 
  
This snip of DIL would replace any 'f' in a string with a 'b' remember DIL is
+
  '''Note'''
not case sensitive so it will also replace an 'F'.
+
  Currently you can only access the single elements of a string you can not set
 +
them.  In the future this will be possible.  You can still accomplish this by
 +
copying one string to the other one element at a time and changing any that you
 +
want something like this.
 +
 
 +
'''Example'''
 +
i:=0;
 +
ln:=length (str);
 +
while (str.[i]<ln)
 +
{
 +
if (str.[i]=="f")
 +
newstr.[i]:="b";
 +
else
 +
newstr:=str.[i];
 +
i:=i+1;
 +
}
 +
str:=newstr;
 +
 
 +
  This snip of Dil would replace any 'f' in a string with a 'b' remember dil is
 +
not case sensitive so it will also replace an 'F'.
 +
 
 +
---~---~---~---~---~---~---~---~---

Latest revision as of 10:45, 4 December 2025


String:
   A string is some text. They are used for a lot of things such as command
arguments, room descriptions etc. String variables are automatically resized and
allocated when you assign them, so you do not have to worry about the string
length nor allocation in your DIL programs. Strings may be compared either with
'==' (equal to),
'!=' (not equal),
'<=' (less than or equal to),
'>=' (greater than or equal to)
'<' (less than),
 '>' (greater than.
  Static strings are defined just as in the rest of the zone, within double
quotations.  Strings may be searched easily with the 'in' operator.  Variables
of type string are saved with DIL programs, if attached to a saved unit.
Example:
  "This is a static string"
Strings may also be added to each other, in an expression.
Example:
  "say "+itoa(42)+" is the answer!"
Example:
  if (self.name == self.names.[1]) ...
  Elements of the string can also be accessed by referencing them by their position.
  Example
  if (str.[3]==f])
  {
  exec ("say The 4th element is a F.",self);
  }
  Note
  Currently you can only access the single elements of a string you can not set
them.  In the future this will be possible.  You can still accomplish this by
copying one string to the other one element at a time and changing any that you
want something like this.
Example
i:=0;
ln:=length (str);
while (str.[i]<ln)
	{
	if (str.[i]=="f")
	newstr.[i]:="b";
	else
	newstr:=str.[i];
	i:=i+1;
	}
	str:=newstr;
  This snip of Dil would replace any 'f' in a string with a 'b' remember dil is
not case sensitive so it will also replace an 'F'.
---~---~---~---~---~---~---~---~---