Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Out of memory on UCase()
Message
De
29/07/2013 14:00:21
 
 
À
29/07/2013 11:36:03
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01579306
Message ID:
01579369
Vues:
51
>>Ok, instead of
>>
>> n = Occurs(....)
>>  for I = 1 to n
>>      xx = At(...., I)
>>  end
>>
>>
>>Consider writing an overload of Occurs which returns a List< int > with all the indexes where there's a match. That way you wouldn't need At() any more
>
>Thanks


Even better with an Enumerator - and ignoreCase if needed
	public static class StringMethods
	{
		public static IEnumerable<int> EnumAt(string searchIn, string searchFor, int startIndex, StringComparison comparison)
		{
			int offset = startIndex;

			while ((offset = searchIn.IndexOf(searchFor, offset, comparison)) != -1)
			{
				yield return offset;
				offset += searchFor.Length;
			}
		}
	}
sample
	public static class MyClass
	{
		static string htmlSample = @"
		<!DOCTYPE html>

		<html lang=""en-GB"">
		<head>
		  <meta charset=""utf-8"">
		  <title>Example of an inline image</title>
		</head>
		<body>
		<imG src=""balconyview.jpg"">
		<Img Src = 'balconyview.jpg' alt='View from my balcony, showing a row of houses, trees and a castle'>
		<iMg src='http://example.com/brokenlink/sunset.gif' alt='Beautiful Sunset' />

		</body>
		</html>
		";

		public static void Main()
		{
			foreach (int index in StringMethods.EnumAt(htmlSample, "<img", 0, StringComparison.InvariantCultureIgnoreCase))
			{
				Console.WriteLine("{0} {1}", index, htmlSample.Substring(index, 4));
			}
			Console.ReadLine();
		}
	}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform