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

do not know how to put \' into string #3036

Closed
bronze1man opened this issue Dec 10, 2019 · 3 comments
Closed

do not know how to put \' into string #3036

bronze1man opened this issue Dec 10, 2019 · 3 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. OS: Playground Bugs/feature requests, that are specific to play.vlang.io. Unit: Documentation Bugs/feature requests, that are related to the documentations.
Milestone

Comments

@bronze1man
Copy link

V version:
OS:
https://vlang.io/play
What did you do?

fn main() { 
	areas := ['game', 'web', '\\\'', 'systems', 'GUI', 'mobile']
        for i,area in areas {
                println('Hello, $area developers!')
        }
} 

got error message:

syntax error: unexpected `', '`, expecting `,`
    1| fn main() { 
@bronze1man bronze1man added the Bug This tag is applied to issues which reports bugs. label Dec 10, 2019
@zeddidragon
Copy link

You escape it once. '\\' will result in a single slash \.

Another option is using raw string: r'\\\' will output \\\

@richgieg
Copy link

One way to put a single quote in a string is to use double quotes to wrap the string (e.g.: "it's one way").

@M4SSD35TRUCT10N M4SSD35TRUCT10N added the OS: Playground Bugs/feature requests, that are specific to play.vlang.io. label Apr 5, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added this to the Beta Release milestone Apr 5, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added the Unit: Documentation Bugs/feature requests, that are related to the documentations. label Apr 5, 2020
@Ivo-Balbaert
Copy link
Contributor

The solution has been given by zeddidragon and richgieg above. The following code works with v 0.1.27 on Windows 10 and the Playground (2 versions that work are given here):

fn main() {
// areas := ['game', 'web', "\'", 'systems', 'GUI', 'mobile']
areas := ['game', 'web', r''', 'systems', 'GUI', 'mobile']
for _, area in areas {
println('Hello, $area developers!')
}
}

Output:
/*
Hello, game developers!
Hello, web developers!
Hello, ' developers!
Hello, systems developers!
Hello, GUI developers!
Hello, mobile developers!
*/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. OS: Playground Bugs/feature requests, that are specific to play.vlang.io. Unit: Documentation Bugs/feature requests, that are related to the documentations.
Projects
None yet
Development

No branches or pull requests

6 participants