String (computing): Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric M Gearhart
imported>Eric M Gearhart
m (copyedit)
Line 7: Line 7:
accessdate=2009-07-04
accessdate=2009-07-04
}}</ref>,  as opposed to integer variables (so called int variables) that can only hold integers (e.g. a number, such as 5) or a "float" variable, which can hold floating point numbers (e.g. numbers with decimal places - 5.5, 6.3, etc.)
}}</ref>,  as opposed to integer variables (so called int variables) that can only hold integers (e.g. a number, such as 5) or a "float" variable, which can hold floating point numbers (e.g. numbers with decimal places - 5.5, 6.3, etc.)


==Various implementations of the String variable type==
==Various implementations of the String variable type==

Revision as of 12:10, 4 July 2009

This article is a stub and thus not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

In computing and more specifically in various programming languages, strings are a variable type that can hold text[1], as opposed to integer variables (so called int variables) that can only hold integers (e.g. a number, such as 5) or a "float" variable, which can hold floating point numbers (e.g. numbers with decimal places - 5.5, 6.3, etc.)

Various implementations of the String variable type

Some languages, such as Java, do require the developer to declare a variable as a String type. Other languages, such as Python automatically "type casts" its variables. This can be helpful or it can also get in the way - if the number 1 is type cast by Python as a string (because it is in a list for example), the developer has to consciously convert that string variable to an 'int' type before any math functions can be performed.

Some developers prefer to type case their own variables (such as in Java, C or C++), while some prefer the automatic type casting that Python does because it can simplify a program. Anyone who has had to debug a Python script to determine that somehow "Python decided this variable was a string instead of an int" understands why some developers become frustrated with dynamic type casting.

A Python string:

MyPythonString = "This is a string"

A Java string:

String MyJavaString = "abc";

Note the difference here - in Python a variable is simply declared, and Python "figures out" if that variable is a string based on its content. In Java (the second example), the keyword String tells Java that the string variable MyJavaString is about to be set.

References

  1. Sun Microsystems. Java API Documentation: Strings. Retrieved on 2009-07-04.