How to Read the Column of a String
In many programming languages a string is a single value usually used to hold text. A string is in contrast to other data types such as an integer, which is only a number, or an array, which is a set of multiple values. In a string a column refers to a particular character. You can pull out a single column or a range of columns from a single string such as the first character or the last five characters in a number of programming languages. In most languages the first character of a string is at position "0" instead of "1" so keep this in mind when counting which column you want to read.
Instructions
-
-
1
Type the following command to read the first column in Ruby:
variable[0]
Replace "variable" with the variable name that contains the string.
For example, if
color = "green"
then
color[0] = "g"
-
2
Type the following code to read the first column of a string in Java:
stringname.charAt( 0 );
Replace "stringname" with the name of your string.
-
-
3
Type the following command to read the fourth column in Python:
mystring[3]
Replace "mystring" with the string's variable name.
For example, if
name = "John"
then
name[3] = "n"
-
1