Strings MathCad Help

Although in most cases the math expressions or variables you work with in Mathcad are real and complex numbers, you can also work with string expressions (also called string literals or string variables), String expressions can include any character you can type at the keyboard, including letters, numbers, punctuation, and spacing, as well as a variety of special symbols as listed in the table of ASCII codes in Appendix A, “Reference.” Strings differ from variable names or numbers because Mathcad always displays them between double quotes. You may assign a string expression to,a variable name, use a string expression as an element of a vector or matrix, or use a string expression as the argument to a function.To create a string expression in math:
• Click on an empty math placeholder in a math expression, usually on the right-hand side of a variable definition. ‘I
• Type the double-quote (,,) key. Mathcad displays a pair of quotes and an insertion line between them Type any combination ofletters, numbers, punctuation, or spaces. Click outside the expression or press the right arrow key when you are finished. To enter a special character corresponding to one of the ASCII codes, do the following: Is := “The result 5 is validl” I
• Click to position the insertion point in the string.
• Hold down the [AI t] key, and type the number “0” followed immediately by the number of the ASCII code using the numeric keypad at the right of the keyboard in number-entry mode.
• Release the [AI t] key to see the symbol in the string. For example, to enter the degree symbol (0) in a string, press down [AI t] and type
“0176” using the numeric keypad. Notice that the double-quote key (,,) has a variety of meanings in Mathcad, depending on the exact location of the cursor in your worksheet. When you type this key in a blank placeholder, Mathcad begins a string expression. As described in “Complex numbers” on page 161, typing the double-quote key after you have selected a math expression creates the complex conjugate of the selected expression. And typing the double-quote key when you see a crosshair cursor in a blank space in the worksheet begins a text region, as described in Chapter 5, “Text.” So when you want to enter a string variable, you must always have a blank placeholder selected. Editing of strings differs from editing of other math expressions because you must use the arrow keys or click outside the string to move out of a string expression. Pressing [Space] or [Tab], which can be used in other expressions to change the position of the editing lines, is interpreted as just another character in string. Figure 8-4 shows examples of strings in math expressions. Valid strings include expressions such as “The Rain in Spain Falls Mainly on the Plain,” “Invalid input: try
a number less than -5,” and “Meets stress requirements.” A string expression in Mathcad, while not limited in size, always appears as a single line of text in your worksheet. Note that a string such as “123,” created in the way described above, is understood by Mathcad to be a string of characters rather than the number 123.

Figure 8-4: Using strings in math expressions.

Figure 8-4: Using strings in math expressions.

Most of Mathcad’s arithmetic operators and built-in functions expect numeric argurnents and will issue error messages when you use string expressions with them. As ‘aescribed in Chapter 12, “Operators,” however, you can use Mathcad’s boolean operators to compare strings. Mathcad also includes a set of specialized stringmanipulation functions as described in Chapter 13, “Built-in Functions.” String expressions are especially useful for generating custom error messages in user-defined functions (see the example at the bottom of Figure 8-4) and in programs, as described in Chapter 18, “Programming.” Use string expressions also to specify system paths for arguments to Mathcad’s data and graphics input and output functions, as described in Chapter 19, “Data Management,” and Chapter 28, “Importing and Exporting Graphics

Posted on November 21, 2015 in Variables and Constants

Share the Story

Back to Top
Share This