digitalmars.D.learn - String cast error
- SomeRiz (21/21) Jun 18 2014 Hi.
- Justin Whear (4/41) Jun 18 2014 The problem is that `system` returns the process exit code (an integer),...
- SomeRiz (9/9) Jun 18 2014 Hi Justin thank you.
- H. S. Teoh via Digitalmars-d-learn (16/31) Jun 18 2014 Try this:
- SomeRiz (5/5) Jun 18 2014 Thanks Teoh
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (17/22) Jun 18 2014 According to its documentation, executeShell() returns a Tuple
- SomeRiz (3/3) Jun 18 2014 @Ali Çehreli
Hi. My code running: http://dpaste.dzfl.pl/2183586524df Output: SerialNumber 927160020XXXX (X = Some Numbers) How do I delete "SerialNumber" text? Example string SomeRiz = system(a); I get an error: b.d(10): Error: cannot implicitly convert expression (system(a)) of type int to string Later; string SomeRiz = cast(string)system(a); I get an error 2: b.d(10): Error: cannot cast system(a) of type int to string How do I delete "SerialNumber" text? I just, want to see the numbers: 927160020XXXX Sorry for my bad english
Jun 18 2014
On Thu, 19 Jun 2014 00:05:36 +0000, SomeRiz wrote:Hi. My code running: http://dpaste.dzfl.pl/2183586524df Output: SerialNumber 927160020XXXX (X = Some Numbers) How do I delete "SerialNumber" text? Example string SomeRiz = system(a); I get an error: b.d(10): Error: cannot implicitly convert expression (system(a)) of type int to string Later; string SomeRiz = cast(string)system(a); I get an error 2: b.d(10): Error: cannot cast system(a) of type int to string How do I delete "SerialNumber" text? I just, want to see the numbers: 927160020XXXX Sorry for my bad englishThe problem is that `system` returns the process exit code (an integer), not the output of the process. Try using std.process.execute or std.process.executeShell.
Jun 18 2014
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 :(
Jun 18 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
Jun 18 2014
Thanks Teoh I'm trying compile but i get an error: b.d(22): Error: function b.extractSerial (string input) is not callable using ar gument types (ProcessOutput)
Jun 18 2014
On 06/18/2014 06:04 PM, SomeRiz wrote:Thanks Teoh I'm trying compile but i get an error: b.d(22): Error: function b.extractSerial (string input) is not callable using ar gument types (ProcessOutput)According to its documentation, executeShell() returns a Tuple consisting of the return status and the output of the executed program: http://dlang.org/library/std/process/executeShell.html Do not print the entire returned Tuple. Instead, print just the .status member of it: auto result = executeShell(a); if (result.status == 0) { // It worked! Now we can get the output: auto output = result.output; // Use 'output' here... } So, 'output' above is what you should pass to extractSerial() function that H. S. Teoh has written: assert(extractSerial(output) == "92716002xxxx"); (I have not tested the code above.) Ali
Jun 18 2014
Ali Çehreli Thanks I'm test code :) Successfully :) Thank you :)
Jun 18 2014