Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Find Number of Repetitions of Substring

using System;
using System.Linq;

public class Program {
	public static int NumberOfRepeats(string str) 
	{	
		int length = str.Length;
		int checkLength = 2;

		while (checkLength < length)
		{
				if (length % checkLength == 0)
				{
						var times = length / checkLength;
						var subStr = str.Substring(0, checkLength);
						var checkStr = string.Concat(Enumerable.Repeat(subStr, times));

						if (checkStr == str)
						{
								return times;
						}
				}

				checkLength++;
		}

		return 1;
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# access control from another thread 
Csharp :: move position smoth unity 
Csharp :: how to store more precise data then float c# 
Csharp :: netmath hack console 
Csharp :: remove language folders build visual studio 
Csharp :: python mokeypatch asser called 
Csharp :: c# generate random key with specified length 
Csharp :: c# picturebox zoom 
Csharp :: translate english to spanish 
Csharp :: Unity SceneLoad by Name in Inspector 
Csharp :: open aspx page c# 
Csharp :: flutter failed asertion 
Csharp :: detect mouse in bottom of screen + unity 
Csharp :: c# control datagridview null value 
Csharp :: tulpep notification window example c# 
Csharp :: how to make a respaen script in unity 
Csharp :: 1.1 0da14962afa287e5ba55c7d30c902392.cloudfront.net w 
Csharp :: C# Check if variables are equal 
Csharp :: dotween do rotate on one axis 
Csharp :: create circumference with nettopologysuite 
Csharp :: how to make projectile track and go to specified enemy in unity 
Csharp :: unity use of possibly unassigned field struct 
Csharp :: how to count specific controls in a container c# 
Csharp :: Linq join update without creating new 
Csharp :: get local position unity 
Csharp :: unity only one component type 
Csharp :: cache.TryGetValue in MemoryCache c# .net 
Csharp :: c# Isolation Levels 
Csharp :: unity screentoworldpoint 
Csharp :: c# get first word of string 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =