Concatenates two strings with a delimiter. - CSharp System

CSharp examples for System:String Convert

Description

Concatenates two strings with a delimiter.

Demo Code


using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using System;/*from  w  ww. j a  va  2s  .c  o  m*/

public class Main{
        /// <summary>
        /// Concats two strings with a delimiter.
        /// </summary>
        /// <param name="s1">string 1</param>
        /// <param name="delim">delimiter</param>
        /// <param name="s2">string 2</param>
        /// <returns></returns>
        public static string AddWithDelim(string s1, string delim, string s2)
        {
            if (string.IsNullOrEmpty(s1)) return s2;
            else return s1 + delim + s2;
        }
}

Related Tutorials