Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Out of memory on UCase()
Message
From
30/07/2013 05:12:42
 
 
To
29/07/2013 14:00:21
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01579306
Message ID:
01579397
Views:
53
>>>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();
>		}
>	}
>
Very neat !!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform