S
S
Sergey Alekseev2018-01-01 15:29:56
PHP
Sergey Alekseev, 2018-01-01 15:29:56

Php, Remove First and Last Character task with codewars, how to solve the problem?

I'm solving a problem on codewars - Remove First and Last Character. You need to remove the first and last character in a string.
PHP7.0 runtime.
My decision:

function remove_char(string $s): string {
  $result = substr($s, 1, -1);
  return $result;
}

And in general, the tests do not pass, the following error falls out:
Failed asserting that two strings are equal.
Expected: Binary String: 0x0a19684834123e
Actual : Binary String: 0x19684834123e
Who knows how to solve this problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
deadem, 2018-01-11
@serj2000

preg_replace('/^.|.$/', '', $s);

A
Andrey Privalov, 2018-01-11
@negasus

Maybe you should use mb_substr? Who knows what lines they check on

I
iRedds, 2018-01-11
@iRedds

Convert string to array
Concatenate string from array slice (without first and last elements)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question