multiply strings by float
This commit is contained in:
parent
c789285e6a
commit
1f59a4a874
3 changed files with 16 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/target
|
||||
.vscode/
|
||||
|
|
1
sm-test-files/hello.sm
Normal file
1
sm-test-files/hello.sm
Normal file
|
@ -0,0 +1 @@
|
|||
fuck java
|
15
src/main.rs
15
src/main.rs
|
@ -1,5 +1,18 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!, {:#?}", env::args());
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let file = fs::read_to_string(&args[1]).expect("Couldnt read file:");
|
||||
println!("{:?}", multiply_strings(file, 3.5));
|
||||
}
|
||||
|
||||
fn multiply_strings(str: String, multiplier: f32) -> String {
|
||||
let mut r: String = String::from(str);
|
||||
let mult_float = multiplier - (multiplier as i32) as f32;
|
||||
let slice = &r.clone()[0..(r.len() as f32 * mult_float) as usize];
|
||||
|
||||
r = r.repeat(multiplier as usize);
|
||||
r += slice;
|
||||
r
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue