working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,997 snippets matching: length

    public by cghersi  246965  1  6  1

    Calculate the occurrences of words in Rss feed

    Creates a dictionary with keys=words and values=occurrences of that word in the given Rss (specified by the URL). The caller should specify the maximum number of items in the returning dictionary and, optionally, the minimum length of the words that will be added to the output.
    public static Dictionary<string, int> ComputeWordsOccurrencesInRss(string url, int maxItems, int minLenOfAcceptedWords = 1)
    {
      Dictionary<string, int> occurrences = new Dictionary<string, int>();
    
      IList<RssReader.RssItem> singleRssResult = RssReader.ReadRss(url, maxItems, true);
      string[] splitted = null;
      foreach (RssReader.RssItem rss in singleRssResult)
      {
        List<string> words = new List<string>();
    
        //split title in words:
        splitted = StringHelper.SplitIntoWords(rss.Title);
        if (splitted != null)
          words.AddRange(splitted);
    
        //split summary in words:
        splitted = StringHelper.SplitIntoWords(rss.Summary);
        if (splitted != null)
          words.AddRange(splitted);
    
        //compute occurrences of words:
        for (int w = 0; w < words.Count; w++)
        {
          string word = words[w].ToLower();
          if (word.Length < minLenOfAcceptedWords)
            continue;
          if (occurrences.ContainsKey(word))
            occurrences[word]++;
          else
            occurrences.Add(word, 1);
        }
      }
    
      return occurrences;
    }
    

    public by michaelp  159491  0  3  0

    Basic way to calculate length of a string

    Basic way to calculate length of a string: gistfile1.txt
    # breaks if string includes a 0
    def string_length(a)
      string = a + "0"
      length = 0
    
      while string[length] != "0"
        length += 1
      end
    
      puts "Your statement is #{length} characters long"
    end
    
    string_length("I am a meat popsicle.")
    
    

    public by Geometry  87468  0  4  0

    Allows to double the Length

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    public static double Length<TEdgeTraits, TFaceTraits, THalfedgeTraits, TVertexTraits>(this PointTriangleMesh<TEdgeTraits, TFaceTraits, THalfedgeTraits, TVertexTraits>.Edge edge) where TVertexTraits : IPoint
    {
        return Distance(edge.Half1.Target.Traits, edge.Half2.Target.Traits);
    }

    public by boxshadow  83060  0  3  0

    SQL Query ordering by character length.

    SQL Query ordering by character length.: charLength.sql
    SELECT 
      * 
    FROM
       badwords 
    ORDER BY CHAR_LENGTH(strBadWord) DESC 
    
    

    public by cghersi  3494  8  7  0

    C#: how to wrap a text inside a given length

    This method helps in wrapping the given text moving the word that pass the threshold to the next line
    static public string WrapText(string inputText, int minLenght, int maxLength)
    {
        // bool ignoreWrap = false;
        string wrappedText = string.Empty;
    
        string[] lines = inputText.Split(new char[] { '\n' });
        foreach (string line in lines)
        {
            string[] words = line.Split(new char[] { ' ', '\r' });
            int lineCounter = 0;
            foreach (string word in words)
            {
                if (word.Trim().Length == 0)
                    continue;
    
                // Next word will pass the max line length => add a newLine
                if (lineCounter + word.Length + 1 >= maxLength)
                {
                    // Split a single word that is longer than the line
                    if (word.Length >= maxLength)
                    {
                        int fragments = word.Length / maxLength + 1;
                        int fragmentStart = 0;
                        int fragmentLength = 0;
                        for (int t = 0; t < fragments; t++)
                        {
                            fragmentLength = (word.Length - fragmentStart > maxLength) ? maxLength : word.Length - fragmentStart;
                            if (lineCounter > 0)
                                wrappedText += Environment.NewLine + word.Substring(fragmentStart, fragmentLength);
                            else
                                wrappedText += word.Substring(fragmentStart, fragmentLength);
                            fragmentStart += fragmentLength;
                        }
                        if (fragmentLength < maxLength)
                        {
                            wrappedText += " ";
                            lineCounter = fragmentLength + 1;
                        }
                        else
                        {
                            wrappedText += Environment.NewLine;
                            lineCounter = 0;
                        }
                        continue;
                    }
                    wrappedText += Environment.NewLine;
                    lineCounter = 0;
                }
                wrappedText += word;
                wrappedText += " ";
                lineCounter += word.Length + 1;
            }
            wrappedText += Environment.NewLine;
        }
        return wrappedText;
    }

    public by cghersi  3299  2  8  0

    C#: How to dinamically check a string and its length using a Regex

    Thsi method creates a Regex by replacing a placeholder as minimum and maximum length (e.g. in case of username and / or password verifiers...). It can be extended also to apply different Regex with respect to some particular business logic.
    static private string s_nameRegEx = @"^[_a-zA-Z][_a-zA-Z0-9-. ]{ç,§}$"; //'ç' is a placeholder for actual minimum length, '§' is a placeholder for actual maximum length
            
    public static bool NameIsValid(string candidateName, int minimumLen, bool checkOnlyLen, int maxLen = int.MaxValue)
    {
        if (candidateName == null)
            return (minimumLen == 0); //return false if there's a minimum len
        string trimmedName = candidateName.Trim();
        if ((trimmedName.Length < minimumLen) || (trimmedName.Length > maxLen))
            return false;
        if (checkOnlyLen)
            return true;
        Regex nameExpr = new Regex(s_nameRegEx.Replace("ç", (minimumLen - 1) + "").Replace("§", (maxLen - 1) + ""));
        return nameExpr.IsMatch(trimmedName);
    }
    

    public by Geometry  886  0  5  0

    GetLength: Gets the length of each dimension of an array.

    Gets the length of each dimension of an array.
    /// <summary>
    ///   Gets the length of each dimension of an array.
    /// </summary>
    /// 
    public static int[] GetLength(this Array array, bool deep = false)
    {
        if (deep && IsJagged(array))
        {
            var rest = GetLength(array.GetValue(0) as Array, deep);
            return array.Length.Concatenate(rest);
        }
    
        int[] vector = new int[array.Rank];
        for (int i = 0; i < vector.Length; i++)
            vector[i] = array.GetUpperBound(i) + 1;
        return vector;
    }

    public by nreyes  3625  3  5  1

    Simple bootstrap log-in form with visual length validation

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Practica 2</title>
    
    	<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    	<!-- Latest compiled and minified CSS -->
    	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    
    	<style>
    		.jumbotron {
    			background: url("http://www.publicdomainpictures.net/download-picture.php?adresar=30000&soubor=yellow-green-blur-background.jpg") no-repeat center center;
    		}
    	</style>
    </head>
    <body>
    	<div class="jumbotron">
    		<div class="container">
    			<div class="row">
    				<div class="col-md-4 col-md-offset-4 form-container">
    					<form role="form">
    						<fieldset>
    							<legend>Formulario Simple</legend>
    							<div class="form-group" id="form-user">
    								<label for="usuario">Usuario</label>
    								<input type="text" class="form-control" id="usuario" placeholder="Naffer Reyes xD">
    								<span class="help-block">Minimo 4 caracteres, maximo 12</span>
    							</div>
    							<div class="form-group" id="form-password">
    								<label for="contrasena">Contraseña</label>
    								<input type="password" class="form-control" id="contrasena">
    								<span class="help-block">Minimo 6 caracteres en una combinacion de letras y numeros</span>
    							</div>
    							<div class="checkbox">
    								<label>
    									<input type="checkbox">Recuerdame
    								</label>
    							</div>
    							<button type="submit" class="btn btn-success">Registrarme</button>
    						</fieldset>
    					</form>
    				</div>
    			</div>
    		</div>
    	</div>
    	
    	<script type="text/javascript">
    		
    		$("#usuario").keyup(function(event) {
    			var texto = $(this).val();
    			if (texto.length < 4 || texto.length > 12) 
    				{
    					$("#form-user").addClass('has-error');
    					$("#form-user").removeClass('has-success');
    				} else
    				{
    					$("#form-user").removeClass('has-error');
    					$("#form-user").addClass('has-success');
    				};
    		});
    
    		$("#contrasena").keyup(function(event) {
    			var texto = $(this).val();
    			if (texto.length < 6) 
    				{
    					$("#form-password").addClass('has-error');
    					$("#form-password").removeClass('has-success');
    				} else
    				{
    					$("#form-password").removeClass('has-error');
    					$("#form-password").addClass('has-success');
    				};
    		});
    	</script>
    	
    
    	
    	<!-- Latest compiled and minified JavaScript -->
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    </body>
    </html>

    public by LaurenceTamatea  2426  0  4  -1

    Strength Length

    Objects have properties and methods using the dot separator
     <!DOCTYPE html>
    <html lang="en">
    
    	<head>
    		<title>STANDARD TEMPLATE</title>
    		<meta charset="utf-8">
    		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    		<style> </style>
    	</head>
    
    	<body>
    
    <div>OBJECT ORIENTED PROGRAMING</div>
    
    
    		<script>
    
    
    		//dat with its own properties and methods//
    
    		var passenger = "I am passenger 3b";
    
    		passenger.length;
    		document.write (passenger.length); //length is a property of the passenger object//
    
    		//document is an object and write is a method//
    
    		</script>
    
        </body>
    
        </html>
                

    public by ibrahimislam  2334  0  5  0

    SELECT Decimal Column With Desired Length and Precision

    SELECT CONVERT(DECIMAL(15,2),<DECIMAL VALUE COLUMN>)
    • Public Snippets
    • Channels Snippets