String
Tipo de dato string que viene dentro de la libreria soroban
stellar contract init strings --name strings#![no_std]
use soroban_sdk::{contract, contractimpl, vec, Env, String, Vec};
#[contract]
pub struct Strings;
#[contractimpl]
impl Strings {
// Crear un nuevo string
pub fn create_string(env: Env, text: String) -> String {
text
}
// Obtener la longitud de un string
pub fn get_length(env: Env, text: String) -> u32 {
text.len()
}
// Comparar dos strings
pub fn compare_strings(env: Env, text1: String, text2: String) -> bool {
text1 == text2
}
// detecta si un strig está vacio
pub fn is_empty(env: Env, text1: String) -> bool {
text1.is_empty()
}
/*está pendiente en las funcioalidades de soroban_sdk::String la funcionalidad directa
de apend o una cobre carga del operador +, por lo tanto usaremos un vector */
pub fn concatenate(env: Env, text1: String, text2: String) -> Vec<String> {
vec![&env, text1, text2]
}
}📌 Explicación general
🛠 Explicación de las funciones
1️⃣ create_string(env: Env, text: String) -> String
create_string(env: Env, text: String) -> String2️⃣ get_length(env: Env, text: String) -> u32
get_length(env: Env, text: String) -> u323️⃣ compare_strings(env: Env, text1: String, text2: String) -> bool
compare_strings(env: Env, text1: String, text2: String) -> bool4️⃣ is_empty(env: Env, text1: String) -> bool
is_empty(env: Env, text1: String) -> bool5️⃣ concatenate(env: Env, text1: String, text2: String) -> Vec<String>
concatenate(env: Env, text1: String, text2: String) -> Vec<String>📌 Resumen






Last updated
Was this helpful?

