Browse Source

Trying to check if a string contains at least one invalid character

master
Julio Biason 4 months ago
parent
commit
417cdaf194
  1. 7
      containstest/Cargo.lock
  2. 6
      containstest/Cargo.toml
  3. 3
      containstest/README.md
  4. 13
      containstest/src/main.rs

7
containstest/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "containstest"
version = "0.1.0"

6
containstest/Cargo.toml

@ -0,0 +1,6 @@
[package]
name = "containstest"
version = "0.1.0"
edition = "2021"
[dependencies]

3
containstest/README.md

@ -0,0 +1,3 @@
# ContaintsTest
Finding a way to check if any of multiple characters exist in string.

13
containstest/src/main.rs

@ -0,0 +1,13 @@
const INVALID: &'static str = " ()[]/\"\\";
fn invalid(check: &str) -> bool {
check.chars().any(|char| INVALID.contains(char))
}
fn main() {
let str = "thisisfine";
println!("{} - {}", str, invalid(str));
let str = "this is not fine";
println!("{} - {}", str, invalid(str));
}
Loading…
Cancel
Save