std.string.strip(char[] str. char delimiters[]) - possible addition?

Alan Knowles alan at akbkhome.com
Thu Mar 23 19:57:57 PST 2006


I needed to strip quote's from a string, and thought this may be a 
useful addition to std.string

(kind of follow's PHP trim() API http://www.php.net/trim)


Regards
Alan



		char[] stripl(char[] s, char[] c)
		{
			uint i;
		
			for (i = 0; i < s.length; i++)
			{
				bool found = false;
				for(uint  ii =0;ii < c.length; ii++) {
					if (c[ii] == s[i]) {
						found = true;
						break;
					}
				}
				if (!found)
					break;
			}
			return s[i .. s.length];
		}
		
		char[] stripr(char[] s, char[] c) /// ditto
		{
			uint i;
		
			for (i = s.length ; i > 0; i--)
			{
				bool found = false;
				
				for(uint ii =0;ii < c.length; ii++) {
					
					
					if (c[ii] == s[i-1]) {
						found = true;
						break;
					}
				}
				if (!found)
					break;
			}
			return s[0 .. i];
		}
		
		char[] strip(char[] s, char[] c) /// ditto
		{
			return stripr(stripl(s,c),c);
		}

	



More information about the Digitalmars-d mailing list