String cast error

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 18 17:40:33 PDT 2014


On Thu, Jun 19, 2014 at 12:31:51AM +0000, SomeRiz via Digitalmars-d-learn wrote:
> Hi Justin thank you.
> 
> I'm using
> 
> executeShell(a);
> 
> Output:
> 
> ProcessOutput(0, "SerialNumber    \r\r\n92716002xxxx \r\r\n\r\r\n")
> 
> How do I delete ProcessOutPut, 0, SerialNumber, \r,\n text?
> 
> I want to see just out: 92716002xxxx
> 
> Sorry for my bad english :(

Try this:

	import std.regex;
	string extractSerial(string input) {
		auto m = input.match(`SerialNumber\s+(\S+)\s+`);
		if (m)
			return m.captures[1];
		else
			throw new Exception("Could not find serial number");
	}

	auto input = "SerialNumber    \r\r\n92716002xxxx \r\r\n\r\r\n";
	writeln(extractSerial(input)); // prints "92716002xxxx"

Hope this helps.


T

-- 
You have to expect the unexpected. -- RL


More information about the Digitalmars-d-learn mailing list