Difference between revisions of "MC-Basic:MID$"

From SoftMC-Wiki
Jump to: navigation, search
(Created page with '{{MC-Basic |SHORT FORM= |SYNTAX= MID$(''<string>, <start>, <number>'') |AVAILABILITY= All versions |DESCRIPTION= The MID$ function returns the specified number of characters …')
 
 
(9 intermediate revisions by 4 users not shown)
Line 12: Line 12:
 
The MID$ function returns the specified number of characters from the string, starting at the character at position ''<start>''. If ''<start>'' is greater than the length of ''<string>'', the returned ''<string>'' is empty.
 
The MID$ function returns the specified number of characters from the string, starting at the character at position ''<start>''. If ''<start>'' is greater than the length of ''<string>'', the returned ''<string>'' is empty.
  
In UTF-8 supporting versions 4.5.1 and higher NULL characters are no longer cut
+
In UTF-8 supporting versions 4.5.1 and higher NULL characters are no longer cut out from strings, resulting in a different behavior:
  
out from strings, resulting in a different behavior:
+
The string resulting from concatenation is composed from 'A''\0''B', i.e. there is a NULL character in the MIDDLE of the string:
 
 
The string resulting from concatenation is composed from 'A''\0''B', i.e., there is a NULL character in the MIDDLE of the string:
 
  
 
Display cuts the string in the middle NULL:
 
Display cuts the string in the middle NULL:
  
-->?"A" + Chr$(0) + "B"
+
-->?"A" + Chr$(0) + "B"
 
+
A
A
 
  
 
Mid$ gives NULL for the second character:
 
Mid$ gives NULL for the second character:
  
-->?Mid$("A" + Chr$(0) + "B", 2, 1)
+
-->?Mid$("A" + Chr$(0) + "B", 2, 1)
 
+
-->
-->
 
  
 
Value of Len is 3:
 
Value of Len is 3:
  
-->?Len("A" + Chr$(0) + "B")
+
-->?Len("A" + Chr$(0) + "B")
 
+
3.000000000000000e+00
3.000000000000000e+00
 
  
 
Len of Chr$(0) is 1:
 
Len of Chr$(0) is 1:
  
In former versions NULL characters could not appear in the middle of strings, since
+
In former versions NULL characters could not appear in the middle of strings, since theconcationation process cut these characters from the resulting string.
 
 
theconcationation process cut these characters from the resulting string.
 
  
 
|TYPE=
 
|TYPE=
''<return value>'': String<br>
+
<''return value''>: String<br>
 
''<string>'': String<br>
 
''<string>'': String<br>
 
''<start>'': Long<br>
 
''<start>'': Long<br>
''<number>'': Long
+
<''number''>: Long
  
 
|RANGE=
 
|RANGE=
''<return value>'': String<br>
+
<''return value''>: String<br>
 
''<string>'': String<br>
 
''<string>'': String<br>
 
''<start>'': 1 to MaxLong<br>
 
''<start>'': 1 to MaxLong<br>
''<number>'': 0 to MaxLong
+
<''number''>: 0 to MaxLong
  
 
|UNITS=
 
|UNITS=
Line 64: Line 57:
  
 
|LIMITATIONS=
 
|LIMITATIONS=
Read-Only.
+
Read only.
  
 
|EXAMPLE=
 
|EXAMPLE=
-->MID$("Hello", 2, 3)<br>
+
<pre>
 ell
+
-->MID$("Hello", 2, 3)
 +
ell
 +
</pre>
  
 
|SEE ALSO=
 
|SEE ALSO=
* [[Axystems:MC-Basic:LEFT$|LEFT$]]
+
* [[MC-Basic:LEFT$|LEFT$]]
* [[Axystems:MC-Basic:RIGHT$|RIGHT$]]
+
* [[MC-Basic:RIGHT$|RIGHT$]]
 
+
[[Category:MC-Basic:String Manipulation|MID$]]
  
 
}}
 
}}

Latest revision as of 09:17, 22 May 2014

The MID$ function returns the specified number of characters from the string, starting at the character at position <start>. If <start> is greater than the length of <string>, the returned <string> is empty.

In UTF-8 supporting versions 4.5.1 and higher NULL characters are no longer cut out from strings, resulting in a different behavior:

The string resulting from concatenation is composed from 'A\0B', i.e. there is a NULL character in the MIDDLE of the string:

Display cuts the string in the middle NULL:

-->?"A" + Chr$(0) + "B"
A

Mid$ gives NULL for the second character:

-->?Mid$("A" + Chr$(0) + "B", 2, 1)
-->

Value of Len is 3:

-->?Len("A" + Chr$(0) + "B")
3.000000000000000e+00

Len of Chr$(0) is 1:

In former versions NULL characters could not appear in the middle of strings, since theconcationation process cut these characters from the resulting string.

Syntax

MID$(<string>, <start>, <number>)

Availability

All versions

Type

<return value>: String
<string>: String
<start>: Long
<number>: Long

Range

<return value>: String
<string>: String
<start>: 1 to MaxLong
<number>: 0 to MaxLong

Scope

Configuration, Task or Terminal

Limitations

Read only.

Examples

-->MID$("Hello", 2, 3)
ell

See Also