MultiLineAppend

jdubs edited this page Oct 21, 2016 · 1 revision

Table of Contents

Overview

Manipulates a string value based on character codes in the value.

Parameters

Value (multiple) The string to be manipulated. A "+" denotes a line break. To access a variable value wrap the name of the variable in "<<>>" Ex: BEGIN:VCARD+VERSION:2.1+N:<>;<>+FN:<> <>+ORG:<>+TEL;HOME;VOICE:123456+TEL;CELL;VOICE:<>+ADR;HOME:;;<

>;+Email;PREF;INTERNET:<>+END:VCARD

SpecName (constant) The name of the variable for operation result assignment

ErrorMessage (multiple | optional) The error message to return when any error occurs.

Synopsis

First looks up any variables in the Value and replaces the token with the variable value. Then breaks the Value into line by replacing the "+" with line break characters.

This document action was originally designed to support the creation of QR Code formatted vCards. It is useful for any number of scenarios. The example above is a test of the vCard format. To read more about vCards go to Wikipedia (http://en.wikipedia.org/wiki/VCard) where you will find the full list of prefixes available.

Source Code

public static void MultiLineAppend(object Value, string SpecName, object ErrorMessage)
{
	Break();
	try
	{
		Regex _regex = new Regex(@"\<\<(?<Variable>[^\$]*?)\>\>", RegexOptions.Multiline);
		StringBuilder sb = new StringBuilder();
		int start = 0;
		string value = (string)Value;
		foreach (Match match in _regex.Matches(value))
		{
			if (match.Index > start)
				sb.Append(value.Substring(start, match.Index - start));
			sb.Append(Variable(match.Groups["Variable"].Value).Value);
			start = match.Index + match.Length;
		}
		if (value.Length > start)
			sb.Append(value.Substring(start));
		sb.Replace("+", "\r\n");
		Variable(SpecName).Value = sb.ToString();
	}
	catch (Exception ex)
	{
		throw new Four51ActionsException(ex.Message, (string)ErrorMessage);
	}
}

Referenced Methods

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.