Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, November 9, 2021

Adding a newline into a string in C# and X++

Below is the sample code we can use for adding a newline after every occurrence of "@" symbol in the string in C#

 using System;

using System.IO;

static class Program
{
    static void Main()
    {
        WriteToFile
        (
        @"C:\test.txt",
        "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@",
        "@"
        );

        /*
        output in test.txt in windows =
        fkdfdsfdflkdkfk@
        dfsdfjk72388389@
        kdkfkdfkkl@
        jkdjkfjd@
        jjjk@ 
        */
    }

    public static void WriteToFile(string filename, string text, string newLineDelim)
    {
        bool equal = Environment.NewLine == "\r\n";

        //Environment.NewLine == \r\n = True
        Console.WriteLine("Environment.NewLine == \\r\\n = {0}", equal);

        //replace newLineDelim with newLineDelim + a new line
        //trim to get rid of any new lines chars at the end of the file
        string filetext = text.Replace(newLineDelim, newLineDelim + Environment.NewLine).Trim();

        using (StreamWriter sw = new StreamWriter(File.OpenWrite(filename)))
        {
            sw.Write(filetext);
        }
    }
}


Below is the sample code we can use for adding a newline the string in X++
textContainer is a string which I'm used in my code to add my concatinated data. 
  if(textContainer)
			textContainer += "\n"
fileData is a string variable and it will be holding my final return value
fileData += System.Text.RegularExpressions.Regex::Replace(textContainer,"\n", System.Environment::NewLine);


What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...