# RecurrencePatternHelper

When working with saving [recurrence patterns](https://www.telerik.com/products/wpf/documentation/controls/radscheduleview/features/recurrence/recurrences-recurrencepattern), the **RadScheduleView**'s API provides us with the **RecurrencePatternHelper** class, which comes from the **Telerik.Windows.Controls.ScheduleView\.ICalendar** namespace. The helper provides two main functions - turning a recurrence pattern into a nicely serialized string for storage and producing a recurrence pattern when you provide that string back to it.

The purpose of this tutorial is to show you how to:

* [Serialize](https://www.telerik.com/products/wpf/documentation/controls/radscheduleview/features/recurrence/recurrences-recurrencepatternhelper#serialize-a-recurrencepattern-to-string) a recurrence pattern to string.

* [Deserialize](https://www.telerik.com/products/wpf/documentation/controls/radscheduleview/features/recurrence/recurrences-recurrencepatternhelper#deserialize-a-recurrencepattern-from-string) a recurrence pattern from string.

## Serialize a RecurrencePattern to String

When you want to turn (serialize) a recurrence pattern into a string, then you need to use the **RecurrencePatternHelper**'s **RecurrencePatternToString()** static method. The method accepts one argument - the pattern that must be serialized and returns the result string.

For example, consider the following **RecurrencePattern** declaration:

```C#
var pattern = new RecurrencePattern()
{
    Frequency = RecurrenceFrequency.Daily,
    DaysOfWeekMask = RecurrenceDays.WeekDays,
    Interval = 3,
    MaxOccurrences = 10
};
```

```VB.NET
	Dim pattern = New RecurrencePattern() With {
	    .Frequency = RecurrenceFrequency.Daily,
	    .DaysOfWeekMask = RecurrenceDays.WeekDays,
	    .Interval = 3,
	    .MaxOccurrences = 10
	}
```

A new daily recurrence pattern is created that occurs only in the week days. The interval between each occurrence is three days. The pattern has a limit of ten occurrences.

The next code snippet demonstrates you how to use the **RecurrencePatternToString()** static method.

```C#
var serializedPattern = RecurrencePatternHelper.RecurrencePatternToString(pattern);
```

```VB.NET
	Dim serializedPattern = RecurrencePatternHelper.RecurrencePatternToString(pattern)
```

After executing the above example the result string will be: **FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR**.

## Deserialize a RecurrencePattern from String

When you want to produce (deserialize) a recurrence pattern from a string, then you need to use the **RecurrencePatternHelper**'s **TryParseRecurrencePattern** static method. The method accepts two arguments:

* The source string - the string which the recurrence pattern will be parsed from.

* The second parameter is an **out** parameter. This is the parsed pattern.

Consider the serialized string from the previous example: **FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR**. If you want to produce a recurrence pattern from that string, invoke the **TryParseRecurrencePattern** method like in the example below.

```C#
var serializedPattern = "FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR";
RecurrencePattern pattern;
RecurrencePatternHelper.TryParseRecurrencePattern(serializedPattern, out pattern);
```

```VB.NET
	Dim serializedPattern As String = "FREQ=DAILY;COUNT=10;INTERVAL=3;BYDAY=MO,TU,WE,TH,FR"
	Dim pattern As RecurrencePattern
	RecurrencePatternHelper.TryParseRecurrencePattern(serializedPattern, pattern)
```

The result will be a new daily recurrence pattern that occurs only in the week days. The interval between each occurrence is three days. The pattern has a limit of ten occurrences.

## See Also

* [RecurrencePattern](https://www.telerik.com/products/wpf/documentation/controls/radscheduleview/features/recurrence/recurrences-recurrencepattern)

* [RecurrenceRule](https://www.telerik.com/products/wpf/documentation/controls/radscheduleview/features/recurrence/recurrences-recurrencerule)
