Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get char from a string #2069

Open
mruz opened this issue Mar 15, 2020 · 3 comments
Open

Get char from a string #2069

mruz opened this issue Mar 15, 2020 · 3 comments
Labels
bug Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details

Comments

@mruz
Copy link
Contributor

mruz commented Mar 15, 2020

$test = "test";
$t = $test[1];
var_dump($t);

string(1) "e"

zephir

char t;
string test = "test";
let t = test[1];
var_dump(t);
ZEPHIR_INIT_VAR(&test);
ZVAL_STRING(&test, "test");
t = ZEPHIR_STRING_OFFSET(&test, 1);
t = t;
ZEPHIR_INIT_VAR(&_10);
ZEPHIR_INIT_NVAR(&_10);
ZVAL_LONG(&_10, t);
zephir_var_dump(&_10);

int(101)

@mruz
Copy link
Contributor Author

mruz commented Mar 26, 2020

A cast char to string workaround:

char t;
string test = "test";
let t = test[1];

var s;
let s = (string) t;

but it's painful if I want to do ord(data[0]), we could play with chr(), but @sergeyklay maybe there is a better way, is it related to #1988?

I think it works if we do it in the loop, but I have to double-check:

int i;
char c;
string test = "test";

for i, c in test {
    var_dump(c, test[i]);
}

@sergeyklay
Copy link
Member

@mruz Thank you for the bug report. I'll try to sort out

@sergeyklay
Copy link
Member

And yes, this is related to #1988

@Jeckerson Jeckerson added the bug label Apr 4, 2021
@Jeckerson Jeckerson added this to the 0.13.x milestone Apr 13, 2021
@Jeckerson Jeckerson modified the milestones: 0.13.x, 0.14.x Sep 12, 2021
@Jeckerson Jeckerson modified the milestones: 0.14.x, Backlog Oct 3, 2021
@Jeckerson Jeckerson added the Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details label Oct 3, 2021
@Jeckerson Jeckerson removed this from the Backlog milestone Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details
Projects
None yet
Development

No branches or pull requests

3 participants