Unable to display new line in Memo field populated by web service

I have an issue the solution to which is probably very simple but I am not able to figure it out :smileylol:

 

I have a memo field in my form that is populated by a web service. This web service is assigning a string to this memo field. The string contains the characters \r\n, which I assumed Metastorm would display as a new line.

 

However, as per the screenshot attached, the memo field is literally displaying the text \r\n instead.

 

I have tried to do a couple of things as a workaround, for example, set the memo field to something like the following:

 

myMemoField = Mstm.ListItems(System.Text.RegularExpressions.Regex.Split(myStringFromWebService, "\r\n"));

 

But this did not work. It looks like it is not able to find "\r\n" in the string.

I also tried specifying "\\r\\n" or "\r\r\n\n" as the separator but that did not work either.

 

However, if I split the string by a normal character (as per the line below), that works:

 

myMemoField = Mstm.ListItems(System.Text.RegularExpressions.Regex.Split(myStringFromWebService, "a"));

 

 

Any ideas how I can make my memo field display the new lines correctly?

Thanks in advance.

 

 

 

 

Tagged:

Comments

  • It looks like you're trying to split on a characters that are also escape sequences in C#. You need to treat them as string literals by prefacing the string with @...

     

    Try this:

     

    myMemoField = Mstm.ListItems(System.Text.RegularExpressions.Regex.Split(myStringFromWebService, @\r\n));

  • Hi Tony,

     

    Thanks for your response.

     

    I tried your suggestion but it still did not work. This is (literally) my line of script:

     

    this.Local.memDriverAddress = Mstm.ListItems(System.Text.RegularExpressions.Regex.Split(responseObject.DriverAddress.FormattedAddress, @\r\n));

     

    The object responseObject.DriverAddress.FormattedAddress is a string that contains the characters "\r\n".

     

    The memo field still looks like per the screenshot.

     

    Would you have any idea why this is not working or how to troubleshoot this issue?

    Thanks in advance.

  • According to the MSDN docs, that regex method you're using is expecting a regular expression as its 2nd arg. You could try to get that working, but honestly, RegEx can get ugly quickly…

     

    It looks like you're just trying to put some delimited text into a memo variable as a Mstm.List.

     

    The product ships with a very, very handy ListConversionLibrary in the Sample Processes folder under the install root folder.

     

    There is a method in this library that does just this:

     

    Local.memDriverAddress = CreateListFromText(responseObject.DriverAddress.FormattedAddress, @\r\n);

     

    The method looks like this:

     

    public static List CreateListFromText(Text input, Text delimiter)
    {
    if (string.IsNullOrEmpty(input)) return List.Empty;
    if (string.IsNullOrEmpty(delimiter)) return List.Empty;

    return new List(input.ToString().Split(new string[] { (string)delimiter }, StringSplitOptions.RemoveEmptyEntries));
    }

     

    You can open the library and copy and paste the single server side script into your project or deploy the library and add it to your project.

     

  • Hi Tony,

    Thanks for your response. Using the 'CreateListFromText' method proposed worked as expected.