Check if a string contains a non-ASCII value in Julia – ascii() Method
Last Updated :
08 Feb, 2024
The ascii()
is an inbuilt function in Julia which is used to convert a specified string to a String type and also check the presence of ASCII data. If the non-ASCII byte is present, throw an ArgumentError indicating the position of the first non-ASCII byte.
Syntax: ascii(s::AbstractString) Parameters:
- s::AbstractString: Specified string
Returns: It returns the converted string if it contain ASCII byte else throw an ArgumentError indicating the position of the first non-ASCII byte.
Example 1:
Python
println(ascii("GFG?GFG"))
|
Output:
ERROR: LoadError: ArgumentError: invalid ASCII at index 4 in "GFG?GFG"
Stacktrace:
[1] ascii(::String) at ./strings/util.jl:479
while loading /home/cg/root/421147/main.jl, in expression starting on line 9
Example 2:
Python
println(ascii("GeeksforGeeks"))
|
Output:
GeeksforGeeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...