working on it ...

Filters

Explore Public Snippets

Sort by

Found 499 snippets matching: trailing

    public by cghersi @ Snip2CodeDev  2677  5  7  1

    C#: Prepare a string of comma-separated values from a collection.

    This method prepares a comma-separated (or any other character specified as 'separator' input) from the given list. It can also remove zero or negative inputs if explicitly required by setting removeZerosOrNegatives=true
    public static string MergeIntoCommaSeparatedString<T>(ICollection<T> idList, bool removeZerosOrNegatives, char separator = ',')
           where T : struct
    {
        string list_ids = string.Empty;
        if (idList != null)
        {
            foreach (T id in idList)
            {
                if (removeZerosOrNegatives && (Convert.ToInt64(id) <= 0))
                    continue;
                list_ids += string.Format("{0}{1}", separator, id);
            }
            list_ids = list_ids.TrimStart(separator);
        }
        return list_ids;
    }
       

    public by cghersi  2751  0  7  0

    How to trim trailing chars and tabs from a given text

    Removes the starting tabs or spaces from each line of the given text: first of all this methods computes the common number of tabs or spaces for all the single lines of the given input text; then trims the common number of such characters, if needed.
            public static string TrimStartingTabsOrSpaces(string text) 
            {
    		    if (string.IsNullOrWhiteSpace(text))
    			    return text;
    		
    		    //split into lines:
                log.DebugFormat("Splitting: {0}", text);
                int posOfSlashN = text.IndexOf(LINE_SEPARATOR);
                if (posOfSlashN < 0)
                {
                    //cannot find line separator, check if at least '\r' is found:
                    log.Debug("Cannot find \\n, trying to find \\r");
                    int posOfSlashR = text.IndexOf('\r');
                    if (posOfSlashR >= 0)
                    {
                        log.Debug("Found \\r, replacing with line correct separator");
                        text = text.Replace("\r", "\r\n");
                    }
                }
    
    		    string[] lines = text.Split(LINE_SEPARATOR);
                log.DebugFormat("found {0} lines", lines.Length);
    
    		    //count the number of tabs and spaces at the start of each line:
    		    int numOfTabs = int.MaxValue;
                int numOfSpaces = int.MaxValue;
    		    foreach (string line in lines) 
                {
                    if (line.IsNullOrWhiteSpaceOrEOF())
                        continue;
    
    			    //check the number of tabs in the current line:
    			    int curNumOfTabs = CountStartingChars(line, '\t');
    			
    			    //refresh the minimum number of tabs of the entire text:
    			    if (curNumOfTabs < numOfTabs)
    				    numOfTabs = curNumOfTabs;
    			
    			    //check the number of spaces in the current line:
    			    int curNumOfSpaces = CountStartingChars(line, ' ');
    			
    			    //refresh the minimum number of spaces of the entire text:
    			    if (curNumOfSpaces < numOfSpaces)
    				    numOfSpaces = curNumOfSpaces;			
    			
    			    if ((numOfTabs == 0) && (numOfSpaces == 0))
    				    break;
    		    }
    		
    		    //if a positive number of tabs have been found in all the lines, 
    		    //trim all the lines of the actual minimum common number of tabs:
    		    if (numOfTabs > 0) 
    			    return TrimStartingChar(lines, numOfTabs);
    		
    		    //if a positive number of spaces have been found in all the lines, 
    		    //trim all the lines of the actual minimum common number of spaces:
    		    if (numOfSpaces > 0) 
    			    return TrimStartingChar(lines, numOfSpaces);
    		
    		    //otherwise, leave the given input untouched:
    		    return text;
    	    }
            private static char LINE_SEPARATOR = '\n';
            private static int CountStartingChars(string line, char c)
            {
                if (string.IsNullOrWhiteSpace(line))
                    return 0;
                for (int pos = 0; pos < line.Length; pos++)
                {
                    if (line[pos] != c)
                        return pos;
                }
                return line.Length;
            }
            private static string TrimStartingChar(string[] lines, int numOfCharsToTrim) 
            {
    		    StringBuilder str = new StringBuilder();
    		    foreach (string line in lines) 
                {
                    if (line.IsNullOrWhiteSpaceOrEOF())
                        str.Append(line);
                    else
                    {
                        str.Append(line.Substring(numOfCharsToTrim));
                        log.DebugFormat("end of line: {0} {1}", PrintChar(line[line.Length - 2]), PrintChar(line[line.Length - 1]));
                    }
                    str.Append(LINE_SEPARATOR);
    		    }
                return str.ToString();
    	    }
            private static char PrintChar(char c)
            {
                switch (c)
                {
                    case '\r': return 'r';
                    case '\n': return 'n';
                    default: return c;
                }
            }

    public by chilly_bang  1855  4  6  0

    Force trailing slash, redirect .html to trailing slash, delete more then one slash

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #Redirects .html to trailing slash
    RewriteRule (.+)\.html$ /$1/ [L,R=301]
    #force trailing slash
    RewriteCond %{REQUEST_URI} !(/$|\.) 
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
    # entfernt mehrfache Slashes
    RewriteCond %{REQUEST_URI} ^(.*)\/\/+(.*)$ 
    RewriteRule ^(.*)$ %1/%2 [R=301,L]
    </IfModule>

    public by viveklucky1848  2072  0  6  0

    Regex remove trailing spaces in editor

    Remove trailing spaces
    Find: \s+$
    Replace with: '' (not even quotes, means empty )
    
    Press "Replace all" button

    public by alihilal  36  0  4  1

    Remove all leading and trailing white spaces of string in Swift

    handy Swift string extension that helps to remove all leading and trailing white spaces in a string https://www.alihilal.com/snippets?id=swift-remove-whitespace-string
    import  Foundation
    extension String {
         func  strip()  -> String{ 
             return   self.trimmingCharacters(in: CharacterSet.whitespaces)
            }
    }
    // White spaced string
    var string = "    Hello, World   "
    string.strip()
    //Result -> "Hello, World"
    
    																																				

    public by simonwalker  183  0  4  0

    Magento 2 Canonical URLs Extension By FME

    Magento 2 Canonical URL extension helps you remove duplicate content issues from your eCommerce website with the addition of canonical Meta tags. You can add Magento canonical tags to products, categories, and CMS pages to define its relevancy with other pages. Magento canonical tags extension can configure the addition of canonical meta tags to a
    // Enter here the actual content of the snippet.						

    public by msdn  194805  0  6  0

    GetParentName: Retreives the parent name from a storage Uri.

    Retreives the parent name from a storage Uri. The BLOB address. The delimiter. If set to true use path style Uris. The name of the parent. Adds the trailing delimiter as the prefix returned by the storage REST api always contains the delimiter. GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob", "/")) will re
    /// <summary>
    /// Retreives the parent name from a storage Uri.
    /// </summary>
    /// <param name="blobAddress">The BLOB address.</param>
    /// <param name="delimiter">The delimiter.</param>
    /// <param name="usePathStyleUris">If set to <c>true</c> use path style Uris.</param>
    /// <returns>The name of the parent.</returns>
    /// <remarks>
    /// Adds the trailing delimiter as the prefix returned by the storage REST api always contains the delimiter.
    /// </remarks>
    /// <example>
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob", "/")) will return "/mycontainer/myfolder/"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder|myblob", "|") will return "/mycontainer/myfolder|"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/myblob", "/") will return "/mycontainer/"
    /// GetParentName(new Uri("http://test.blob.core.windows.net/mycontainer/", "/") will return "/mycontainer/"
    /// </example>
    internal static string GetParentName(Uri blobAddress, string delimiter, bool usePathStyleUris)
    {
        CommonUtils.AssertNotNull("blobAbsoluteUriString", blobAddress);
        CommonUtils.AssertNotNullOrEmpty("delimiter", delimiter);
    
        string containerName;
        Uri containerUri;
        GetContainerNameAndAddress(blobAddress, usePathStyleUris, out containerName, out containerUri);
    
        // Get the blob path as the rest of the Uri
        var blobPathUri = containerUri.MakeRelativeUri(blobAddress);
        var blobPath = blobPathUri.OriginalString;
    
        if (blobPath.EndsWith(delimiter))
        {
            blobPath = blobPath.Substring(0, blobPath.Length - delimiter.Length);
        }
    
        string parentName = null;
    
        if (string.IsNullOrEmpty(blobPath))
        {
            // Case 1 /<ContainerName>[Delimiter]*? => /<ContainerName>
            // Parent of container is container itself
            parentName = containerName + delimiter;
        }
        else
        {
            var parentLength = blobPath.LastIndexOf(delimiter);
    
            if (parentLength <= 0)
            {
                // Case 2 /<Container>/<folder>
                // Parent of a folder is container
                parentName = containerName + delimiter;
            }
            else
            {
                // Case 3 /<Container>/<folder>/[<subfolder>/]*<BlobName>
                // Parent of blob is folder
                parentName = blobPath.Substring(0, parentLength + delimiter.Length);
            }
        }
    
        return parentName;
    }

    public by msdn  1864  0  7  0

    AllocHGlobal: Allocates from unmanaged memory to represent a structure with a variable length array at the end and marshal these structure elements. It is the callers responsibility to marshal what preceeds the trailinh a...

    Allocates from unmanaged memory to represent a structure with a variable length array at the end and marshal these structure elements. It is the callers responsibility to marshal what preceeds the trailinh array into the unmanaged memory. ONLY structures with attribute StructLayout of LayoutKind.Sequential are supported. Type of the traili
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Runtime.CompilerServices;
    using System.Runtime.ConstrainedExecution;
    using System.Runtime.InteropServices;
    using System.Security;
    using Microsoft.Win32.SafeHandles;
    
    /// <summary>
    /// Allocates from unmanaged memory to represent a structure with a
    /// variable length array at the end and marshal these structure
    /// elements. It is the callers responsibility to marshal what preceeds
    /// the trailinh array into the unmanaged memory. ONLY structures with
    /// attribute StructLayout of LayoutKind.Sequential are supported.
    /// </summary>
    /// <typeparam name="T">Type of the trailing array of structures</typeparam>
    /// <param name="prefixBytes">Number of bytes preceeding the trailing array of structures</param>
    /// <param name="values">Collection of structure objects</param>
    /// <param name="count"></param>
    /// <returns>SafeHGlobalHandle object to an native (unmanaged) structure
    /// with a trail array of structures</returns>
    public static SafeHGlobalHandle AllocHGlobal<T>(int prefixBytes, IEnumerable<T> values, int count) where T
                                                                                                       : struct
    {
        Debug.Assert(typeof(T).StructLayoutAttribute.Value == LayoutKind.Sequential);
    
        SafeHGlobalHandle result = AllocHGlobal(prefixBytes + Marshal.SizeOf(typeof(T)) * count);
    
        IntPtr ptr = result.pointer + prefixBytes;
        foreach (var value in values)
        {
            Marshal.StructureToPtr(value, ptr, false);
            ptr += Marshal.SizeOf(typeof(T));
        }
    
        return result;
    }

    public by msdn  1519  0  6  0

    GetContainerName: Retrieves the container part of a storage Uri, or "$root" if the container is implicit.

    Retrieves the container part of a storage Uri, or "$root" if the container is implicit. The blob address. If set to true use path style Uris. Name of the container. The trailing slash is always removed. GetContainerName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob")) will return "mycontainer" GetConatinerName(new Uri("
    /// <summary>
    /// Retrieves the container part of a storage Uri, or "$root" if the container is implicit.
    /// </summary>
    /// <param name="blobAddress">The blob address.</param>
    /// <param name="usePathStyleUris">If set to <c>true</c> use path style Uris.</param>
    /// <returns>Name of the container.</returns>
    /// <remarks>
    /// The trailing slash is always removed.
    /// <example>
    /// GetContainerName(new Uri("http://test.blob.core.windows.net/mycontainer/myfolder/myblob")) will return "mycontainer"
    /// GetConatinerName(new Uri("http://test.blob.core.windows.net/mycontainer/")) will return "mycontainer"
    /// GetConatinerName(new Uri("http://test.blob.core.windows.net/myblob")) will return "$root"
    /// GetConatinerName(new Uri("http://test.blob.core.windows.net/")) will throw ArgumentException
    /// </example>
    /// </remarks>
    internal static string GetContainerName(Uri blobAddress, bool usePathStyleUris)
    {
        string containerName;
        string blobName;
    
        GetContainerNameAndBlobName(blobAddress, usePathStyleUris, out containerName, out blobName);
    
        return containerName;
    }

    external by IlanFrumer  180145  1  4  0

    ui router - trailing slash

    ui router - trailing slash: ui-router-trailing-slash.coffee
    app.config ($urlRouterProvider)->
    
      ##############################################################################################################################
      # https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-make-a-trailing-slash-optional-for-all-routes
      ##############################################################################################################################
    
      $urlRouterProvider.rule ($injector, $location)->
    
        path = $location.path()
        
        # Note: misnomer. This returns a query object, not a search string
        search = $location.search()
        
        # check to see if the path already ends in '/'
        return if path[path.length - 1] is "/"
        
        # If there was no search string / query params, return with a `/`
        return path + "/"  if Object.keys(search).length is 0
        
        # Otherwise build the search string and return a `/?` prefix
        params = []    
        angular.forEach search, (v, k) ->
          params.push k + "=" + v
    
        path + "/?" + params.join("&")
    
      $urlRouterProvider.otherwise('/')
    
    
    • Public Snippets
    • Channels Snippets