Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
30 views

Assign a portion of an array into another array

I want to create a new string array with elements from another array. After that, my randomization will go through this new array. What is the best way to do this? Here's example code piece: // SPDX-...
1
vote
0answers
16 views

Algorithmic complexity of abi.encodePacked

What is the algorithmic complexity of repeated string concatenation via abi.encodePacked? Specifically, if we have m strings s_i for i in [1, m], each of identical length n, is abi.encodePacked(s_1, ...
0
votes
1answer
18 views

Store utf-8 in string variable

I know it is possible to store utf-8 text in string variable. but it gives error. contract test1{ string text = "ğğğğ şşşş üüüü"; }
1
vote
0answers
22 views

(Update Solidity ^0.8.0) How to check string length? [duplicate]

There is a question about this from four years ago. One answer suggests using bytes(str).length, which still works as described, as an estimate that potentially overestimates the number of characters. ...
0
votes
0answers
24 views

Escaping HTML special characters in Solidity

I realize I am not supposed to do this, and yet I am curious about the least-bad approach. Will the code below work? It is based on some of Uniswap's code. function escapeHTML(string memory input) ...
0
votes
1answer
116 views

How to split a string in solidity?

I'm using the OpenZeppelin Preset of the 1155 Token Standard. (https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token/ERC1155/presets) I'm able to mint tokens with that and ...
0
votes
0answers
34 views

Encrypt and decrypt a string in solidity

I would like to write a function to encrypt a string by decreasing it's length then it will be possible to reach the original one too ( two way encryption ). I don't care about the security. my ...
0
votes
0answers
30 views

Why is `abi.encodePacked` preferred to `bytes` in string comparison?

The official documentation recommends to test string equality using keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2)) Why is this to be preferred to keccak256(bytes(s1)) == keccak256(...
0
votes
0answers
43 views

Return JSON from view function

I'm trying to find the "best practice" to return a JSON formatted string from a view function. Basically, I plan to loop through a set of data stored in contract state, build it all into a ...
0
votes
1answer
34 views

String compare function works when defined in contract but not in library

I have a very basic string helper library that defines a function to compare two strings like so: library StringLib { function compareTwoStrings(string memory s1, string memory s2) public ...
0
votes
1answer
29 views

String to Bytes Converts to Incorrect Value

I have a string array stored in memory as https://cloudflare-ipfs.com/ipfs/QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s This should convert to ...
0
votes
0answers
9 views

Is there a solidity library with Java StringBuffer like utility?

I am going to be dynamically constructing some JSON. It is a pure view function so dont care about gas cost. Still, it seems lots of string concatenation is very slow, at least in Remix. Maybe some ...
0
votes
0answers
30 views

Only use ASCII strings in solidity?

So I know that strings are UTF8 by default. However, that comes with its set of problems, like taking more storage. Is there a way to only allow ASCII in my contract?
0
votes
0answers
95 views

Recover account from 64-byte string

In October 2015, I generated an account and backed up two things: the address, and a mysterious 64-byte string. I can see the correct balance on the address, so no problem here. I initially assumed ...
0
votes
0answers
311 views

TypeError: Type function (uint256) pure returns (string memory) is not implicitly convertible to expected type string memory

In Remix I'm getting this strange error while calling Strings.sol library: TypeError: Type function (uint256) pure returns (string memory) is not implicitly convertible to expected type string memory. ...
0
votes
0answers
17 views

Invalid string crashes Remix IDE

If I have an empty function that accepts a string memory input, and if I pass invalid strings like: " "a """ the Remix IDE crashes. Is this just an issue with Remix? If not, ...
0
votes
0answers
25 views

Any known hacks by storing string with non-alphanumeric values?

I was checking out hashmasks smart contracts, and they have the following rules for names: No name can be identical There is a limit of 25 symbols (including spaces) Uniqueness is case insensitive (i....
0
votes
1answer
61 views

Solidity: How to represent bytes32 as string

This may be simple in other languages but I can't figure out how to do it in Solidity. I have a bytes32 like this 0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712. I don't want to ...
0
votes
0answers
28 views

Concatenating strings overwriting a variable

I'm building a SC with many strings and concatenations. Is there any way to overwrite a string and, moreover, not using an auxiliary method? Something like: // SPDX-License-Identifier: MIT pragma ...
2
votes
1answer
227 views

How to concatenate an address to a string in solidity

I am trying to find the correct way to concatenate an Ethereum address to a string in Solidity v0.6.7 I tried the following but it did not seem to work : function append(string a, address b) ...
1
vote
0answers
9 views

Check string similarity percentage

How can I efficiently check the similarity of two strings? Or better yet, if I have an array of strings, I want to check that the given string is less than e.g. 80 % similar to any of the other ...
0
votes
0answers
72 views

VM error: invalid opcode. invalid opcode The execution might have thrown

I am trying to take in a 512 character long string and extract the first 312 characters from the string. This is my test on a small scale, tryign to extract 12 characters out from a 30 character long ...
0
votes
2answers
100 views

How to ensure that a string parameter to a function is not empty?

Lets say that I have a function which needs two string parameter , function data(string memory _firstname, string memory _lastname) public { buyer[msg.sender] = Buyer(_firstname, _lastname); } Now, I ...
0
votes
2answers
383 views

how to set a require for a string to not be null

I want to write a require condition for string that string variable could not be null. How to write because string is not taking the != operator function createOrder(address _seller, string memory ...
3
votes
1answer
512 views

Can I use an emoji as part of a string in Solidity?

Can I use an emoji in Solidity?
0
votes
0answers
62 views

String to float maintaining decimal places

I've seen some thread already however I haven't found anywhere a way of converting a string number to float number and maintaining the decimals. ie "27.546" to 27.546
3
votes
1answer
572 views

In solidity, how to copy a string or pass it by value?

In this example I only modify string a, but both a and b are changed. It seems like the string wasn't copied. I only want to change a. How do you copy a string and how do you pass a string by value to ...
3
votes
1answer
640 views

What is the maximum size of string which we can store on solidity?

Is there a limit to the size of a string that we can store on the Ethereum blockchain?
2
votes
1answer
511 views

Calling a string variable

Update2: Ismael highlighted that upgrading drizzle and Web3 were crucial. I was using drizzle 1.3 and Web3 1.0. So, using the same Solidity code, I can now read a string array into a webpage, using ...
0
votes
1answer
192 views

How do I order strings in Solidity?

I'm a newbie to smart contract development, and I'm looking to order strings using solidity, I don't care that much what kind of ordering method (alphabetical for example) is used, I just want it to ...
0
votes
2answers
2k views

Solidity Split Comma-Delimited String into Individual words

Since Solidity functions can't accept String Arrays as arguments, I'm trying instead to pass in a long comma-delimited string, and then convert it to an array of strings on the fly. I'm close - but ...
0
votes
1answer
875 views

How to concatenate uint to address in solidity?

I would like to concatenate an Ethereum address to an uint in Solidity. How can I do that?
2
votes
1answer
292 views

TypeError: Type string calldata slice is not implicitly convertible to expected type string memory

I want to slice a string and save it to a memory or storage variable. Is this possible? function test(string calldata _input) external{ string memory something = _input[1:3]; } I am ...
0
votes
0answers
27 views

Making sure a string (input/output) is less then 64 characters

I'm working though some basic solidity tutorials using remix. I'm having trouble with the concept that there is no way to edit a string built into the language. In other programing languages I would ...
0
votes
0answers
44 views

Splice an Address

So in javascript I can take a string such as yourString[7] and get the 8th character within that string returned to me in string format. I want to take the last character in an Ethereum address, be an ...
0
votes
0answers
30 views

Compare strings

I want to compare two strings but, by using: require(keccak256(abi.encodePacked(_car))==keccak256(abi.encodePacked(car))); I get the following error: InternalCompilerError: Unknown ...
0
votes
1answer
320 views

Convert a string in scientific notation to a number

my smart contract uses an Oracle to retrieve the price. The price is returned as a string in scientific notation, for example, "3e-8". How I can convert this to number (uint)? The token has ...
0
votes
0answers
77 views

Passing a hash value to function

I'm trying to authenticate users by comparing the hashes created by backend server and contract. Seems like "byte32" values cannot be coerced into strings. So, instead I'm converting it into ...
0
votes
1answer
410 views

Explicit type conversion not allowed from "string memory" to "uint256"

I'm using an oracle to get results from a custom api. The result is in string by default. I want to convert it to uint256, so that I can perform basic arithmetic functions. Here's my code: function ...
1
vote
1answer
94 views

In Solidity, Is there any situation, when string is necessary?

In Solidity, Is there any situation, when string is necessary? Please can u explain when I should use string instead of bytes or bytesN? Thanks!
0
votes
0answers
557 views

How can I return string array in solidity?

This is my struct: struct Token { address tokenAddress; uint256 minAmount; bool emergencyUnlock; TokenStatus status; string name; uint256 decimal; string thumbnailUrl; } ...
1
vote
0answers
144 views

Gas-efficient string concatenation

My use-case requires that I feed my contract with a long string (Base64 data), which requires to split it and send it over several transactions so as to not reach gas limit. Then the contract rebuilds ...
0
votes
1answer
106 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
1
vote
1answer
31 views

How to save long textual data on blockchain? [closed]

I need to write blogs and save them on blockchain. What are efficient possibilities to store such data on blockchain? Thanks for reading the question, already appreciate your time.
0
votes
1answer
75 views

Where does the length parameter end and the actual string start in an abi encoded string?

Assuming I decided to ABI encode a very long string (for the purpose of this question I just picked an arbitrary 5-paragraph lorem ipsum text generate by https://www.lipsum.com/feed/html) and get out ...
0
votes
1answer
91 views

Why does declaring returns type bytes memory give a compiler error?

If we have the following code: pragma solidity >= 0.5; contract stringsContract { function takesTwo(string memory str, uint idx) public pure returns (bytes memory) { bytes memory ...
1
vote
1answer
99 views

Garbage in string parameters of events

I have an event defined like this: event Created( address indexed target, string indexed name ); I do emit Created(..., _name); // called function with _name = "comment" which gives ...
1
vote
1answer
613 views

Bytes memory as a function parameter increase gas cost

I've a smartcontract compiled with pragma solidity ^0.4.0; version and one function receives a bytes parameters which contain a long string. In these version it doesnt need to set the parameters as "...
0
votes
1answer
338 views

Solidity. Concatenate and hash two strings

Hi all I need tho sha256 two strings. I am new to solidity. This is what I've got: function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(...
0
votes
1answer
48 views

Solidity. Concatenate hash w address. TypeError: Operator + not compatible with types string memory and address payable

I am trying to do something simple: examsFinalHash = keccak256(examHash + msg.sender); but I get the following error: TypeError: Operator + not compatible with types string memory and address ...