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

A string issue when dealing with Chinese. #534

Closed
dingdinglz opened this issue Nov 3, 2024 · 2 comments · Fixed by #535
Closed

A string issue when dealing with Chinese. #534

dingdinglz opened this issue Nov 3, 2024 · 2 comments · Fixed by #535

Comments

@dingdinglz
Copy link

When I run this code,I can't get the wanted response.

package main

import (
	"github.com/robertkrimen/otto"
)

func main() {
	vm := otto.New()
	vm.Run(`
	var Message = "发送 213123";
    index = (Message).indexOf(' ') + 1;
	console.log(Message.slice(0,index-1));
	`)
}

I think the correct res is

ISSUE2

But I get this

ISSUE3

Maybe there are some errors in otto?

I can't sure,so I send this issue.Maybe you can help me.I think it may link to Chinese.

When I replace the "发送" with "send" , I can get the right answer.

Thank you for your help.

stevenh added a commit that referenced this issue Nov 3, 2024
Fix string slice and replace so they work correctly with utf8
characters.

Fixes #534
@stevenh
Copy link
Collaborator

stevenh commented Nov 3, 2024

Thanks for the report @dingdinglz could you try #535 to confirm it fixes your use case please.

stevenh added a commit that referenced this issue Nov 3, 2024
Fix string slice and replace so they work correctly with utf8
characters.

Fixes #534
@dingdinglz
Copy link
Author

Thank you for your help.The problem has been corrected.

stevenh added a commit that referenced this issue Nov 4, 2024
Fix string slice and replace so they work correctly with utf8
characters.

Fixes #534
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants