StringBuffer
struct StringBuffer
StringBuffer is a mutable string.
In Navi string
is immutable, so if you want to build a string, you can use StringBuffer
.
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("Hello, ");
buf.push_string("World!");
assert_eq buf.to_string(), "Hello, World!";
Methods
Return the bytes of StringBuffer.
Return the bytes of StringBuffer.
Return the bytes of StringBuffer.
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("hello world");
assert_eq buf.bytes(), "hello world".bytes();
Truncate the StringBuffer to given length.
Truncate the StringBuffer to given length.
Truncate the StringBuffer to given length.
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("hello world");
assert_eq buf.len(), 11;
buf.truncate(5);
assert_eq buf.len(), 5;
assert_eq buf.to_string(), "hello";
reset
pub fn reset(self)
Reset the buffer.
reset
pub fn reset(self)
Reset the buffer.
Reset the buffer.
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("hello world");
assert_eq buf.len(), 11;
buf.reset();
assert_eq buf.len(), 0;
Return the bytes length of StringBuffer
.
Return the bytes length of StringBuffer
.
Return the bytes length of StringBuffer
.
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("hello world");
assert_eq buf.len(), 11;
Pops the last char from the buffer.
Pops the last char from the buffer.
Pops the last char from the buffer.
Example
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("Hello");
assert_eq buf.pop(), 'o';
assert_eq buf.to_string(), "Hell";
Appends a char to the buffer.
Appends a char to the buffer.
Appends a char to the buffer.
Example
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push('H');
buf.push('e');
buf.push('l');
buf.push('l');
buf.push('o');
assert_eq buf.to_string(), "Hello";
push_string
pub fn push_string(self, s: string)
Appends a string to the buffer.
push_string
pub fn push_string(self, s: string)
Appends a string to the buffer.
Appends a string to the buffer.
Example
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
buf.push_string("Hello, ");
buf.push_string("World!");
assert_eq buf.to_string(), "Hello, World!";
new
pub fn new(capacity: int = 0): StringBuffer
Creates a new StringBuffer
.
new
pub fn new(capacity: int = 0): StringBuffer
Creates a new StringBuffer
.
Creates a new StringBuffer
.
Example
nv
use std.str.StringBuffer;
let buf = StringBuffer.new();
assert_eq buf.to_string(), "";