# Methods in Expressions

Methods are similar to functions; however, they always relate to a variable of a specific type (for example, a string, a number, a dictionary) and are used to work specifically with that type of variable. The method name is written after the variable name, separated by a dot. A method may not have any arguments, in which case parentheses are not needed after it. Some methods, like functions, can have one or more arguments, which are written in parentheses after the method name. Methods can either return a value or modify the value and state of the variable or object to which they belong.

**Examples of Using Methods:**

* `$МояТекстоваяСтрока.Length` – the Length method is used with text strings, lists, dictionaries, and some other composite data types. When used with text strings, the Length method returns their length in characters (the number of characters that make up the string), and when used with composite data types (lists, dictionaries), it returns the number of their elements. The Length method does not require any arguments and is therefore used without parentheses.
* `$MyString.Replace`("text", "newtext") – the Replace method is used with text strings, searches the string for all occurrences of the text specified in the first argument, and replaces them with the text specified in the second argument. As with functions, you can use not only constants as arguments but also other variables and expressions with them. The Replace method does not modify the original string but returns the result of its execution. For example, it can be used in an Assign block to assign the string returned by this method to another variable.

Methods can be used in a "chain." For example, the following expression is valid, and its result will be the length of the new string obtained after replacing all occurrences of "text" with "newtext" in the string stored in the variable `$MyString`:

`$MyString.Replace("text", "newtext").Length`

Some methods provide access to individual elements of composite objects, and they are called "properties." For example, if you use the Get POP3 Mail Messages block to retrieve new email messages, the retrieved messages will be saved in the variable specified in the Result property. Let's say the variable `$Result` is specified there. The type of this variable is a list of objects of type MailMessage. Suppose you want to access the sender's address of the first of the retrieved messages. Since `$Result` in this case is a list, you can access its first element by specifying the index in square brackets: `$Result[0]`. Remember that the indices of all composite elements start from zero, not one. This way, we access the composite object MailMessage, which contains all the information about each message individually. The reference at the bottom of the Edit Expression window suggests that the sender's address is contained in the From property and its subproperty Address. Thus, to access the sender's address in the first retrieved message, we need to use the following expression:

`$Result[0].From.Address`

The result of evaluating this expression will be a text string. It can then be displayed on the screen, written to a file, placed in a table cell, etc. Remembering that methods and properties can be "chained" together, we can find the length of the sender's address in characters with the following expression:

`$Result[0].From.Address.Length`

Alternatively, we can replace the "@" character in the sender's address with the string "-at-" using the following expression:

`$Result[0].From.Address.Replace("@", "-at-")`

As with functions, you can view the list of all available methods, their arguments, and examples of their usage in the reference of the Edit Expression window. There, you can also find examples of forming arguments for some special functions. For example, the "DataTime Formats" section contains examples of arguments for date and time formatting functions and blocks. You can also find examples of breaking down composite objects into individual properties. For instance, all properties of the aforementioned MailMessage object are contained in the "Mail Message examples" section of the reference.
