Questions tagged [string]

https://docs.soliditylang.org/en/v0.8.12/types.html

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

Copying strings and bytes from memory to storage via storage references

What's the proper way to copy a string (or bytes) from memory to storage? When copied directly into a state variable lvalue (or into a mapping), there's no problem, but when assigning a string memory ...
user avatar
0 votes
2 answers
22 views

How to add variable into the string in solidity?

I want to add the extractedStr variable into the path? bytes memory extractedStr; string memory combine = '<path d="string(extractedStr)" fill="#FFFFFF"/>';
user avatar
1 vote
1 answer
46 views

Operator += not compatible with types String memory and bytes memory?

How can I add, string(b[i] to number & alpha variable? bytes memory number; bytes memory alpha; function getNumAndAlpha() public pure external returns( bytes n, bytes a){ ...
user avatar
0 votes
1 answer
49 views

How to encode string as bytes array?

A similar question has been asked but using web3 in java, however, I would like to encode a string to bytes[] in solidity itself.
user avatar
  • 230
0 votes
1 answer
35 views

How To Convert Hex String to A Uint in Solidity ^8.0.0

I have this function that converts a unit to a hex string: function uintToHexString(uint i) public pure returns (string memory) { if (i == 0) return "0"; uint j = i; uint length; ...
user avatar
  • 113
0 votes
1 answer
17 views

How many methods do we have to keep String type in Solidity?

How many methods do we have to keep String type in Solidity? Explain the Visibility Quantifiers in Solidity language in detail
user avatar
0 votes
1 answer
39 views

concatenated string reason message in require() not displaying

I'm using Solidity 0.8.13 and Truffle 5.5.6. I'm just trying to debug a transaction call that fails then reverts when I do truffle migration. I temporarily changed my onlyOwner modifier to make the ...
user avatar
0 votes
2 answers
215 views

Convert bytes to hexadecimal string in solidity

In a smart contract I have stored a bytes4 value: 0xa22cb465. I'd like to parse this value as a string: string memory test = "0xa22cb465" I've only stumbled upon explanations on how to ...
user avatar
0 votes
1 answer
18 views

when i call my function metamask telling "this operation is expected to fail"

Hi guys im trying to create question challenge dapp and i have a checkAnswer() function can accessable from frontend. My question struct: struct Question{ string qDesc; uint qPrize;...
user avatar
0 votes
1 answer
14 views

bytes and uint concatenation returns \u0004 instead it should show 4 only? What is the problem?

I am trying to concatenate byte and uint in my project. I am using the following logic I found somewhere: bytes data = abi.encodePacked("Gold_",Gold); where Gold contains a uint8 number. ...
user avatar
0 votes
0 answers
22 views

Why are string operations costly? Can someone explain how this will effect gas prices?

I am new to solidity and while writing a contract I want length of a string for this, I had to first covert to bytes and then find the length. Why are strings treated differently. If length operation ...
user avatar
1 vote
1 answer
80 views

Solidity - How to split the URL?

I have an ipfs URL stored in a variable named string memory _uri and I am setting it to this in the constructor: "ipfs://QmPsG54TQRaeuqRexDXxd77E916zMugjsqmifH2QTvAmxr/{id}.json" and I want ...
user avatar
  • 118
1 vote
2 answers
19 views

Can strings be passed between contracts

I want to call a function from another contract. Can I pass a string? IUpgrade(upgradeAddress).wrap(label, wrappedOwner, _fuses, resolver); label is a string. I read somewhere that you can't pass ...
user avatar
  • 11
0 votes
0 answers
72 views

How to remove the last element of a string in Solidity

I am trying to get better at strings and bytes manipulation. But the general lack of built-in functions is making my life much harder than it should. Basically, I tried to write a solidity function ...
user avatar
  • 636
0 votes
0 answers
91 views

Solidity (find a word in a string and replace it)

I am learning solidity string/byte manipulation and I am trying to create a Solidity function that finds specific words in a string/format and replaces them with given variables to return "edited&...
user avatar
  • 636
0 votes
1 answer
81 views

Storing image URLs in Solidity

I have a very basic but functional smart contract which stores an image URL (and some other fields) for front-end use. However, while it works with shortened image URLs, most URLs are too long, ...
user avatar
0 votes
0 answers
40 views

String limitation in Solidity

I am sending some data as a string to a function in Smart Contract but it seems that there is a limitation. I can send this string: 1643934348.9036129,1643934348.9495316?1487.4277,1627.4347?0.1,0.0?...
user avatar
  • 11
0 votes
1 answer
22 views

Multidimensional String arrays are not supported - Vyper

Whenever I try to make a list of strings (2D array), I get this error Multidimensional String arrays are not supported. This is the code I tried: names: String[30][100]. Does anyone know how to help? (...
user avatar
0 votes
1 answer
79 views

Concatenating values in Solidity

I need to concatenate two strings in Solidity. I'm having problem with below code. I reveive message error: Member "concat" not found or not visible after argument-dependent lookup in type(...
user avatar
  • 3
2 votes
0 answers
300 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-...
user avatar
1 vote
0 answers
37 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, ...
user avatar
  • 113
0 votes
1 answer
54 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 = "ğğğğ şşşş üüüü"; }
user avatar
  • 103
1 vote
0 answers
28 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. ...
user avatar
  • 121
0 votes
0 answers
168 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) ...
user avatar
  • 123
0 votes
1 answer
591 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 ...
user avatar
0 votes
0 answers
108 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 ...
user avatar
1 vote
0 answers
148 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(...
user avatar
  • 11
0 votes
0 answers
135 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 ...
user avatar
1 vote
1 answer
236 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 ...
user avatar
  • 175
0 votes
1 answer
35 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 ...
user avatar
  • 113
0 votes
0 answers
13 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 ...
user avatar
  • 133
0 votes
0 answers
77 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?
user avatar
  • 101
0 votes
0 answers
116 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 ...
user avatar
0 votes
1 answer
318 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 ...
user avatar
  • 1
2 votes
1 answer
694 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) ...
user avatar
1 vote
0 answers
12 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 ...
user avatar
1 vote
2 answers
489 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 ...
user avatar
0 votes
2 answers
825 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 ...
user avatar
  • 1
3 votes
1 answer
768 views

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

Can I use an emoji in Solidity?
user avatar
0 votes
0 answers
131 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
user avatar
4 votes
1 answer
1k 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 ...
user avatar
3 votes
1 answer
1k 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?
user avatar
2 votes
1 answer
672 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 ...
user avatar
0 votes
1 answer
259 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 ...
user avatar
  • 103
1 vote
2 answers
3k 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 ...
user avatar
  • 785
0 votes
1 answer
1k 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?
user avatar
  • 277
2 votes
1 answer
707 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 ...
user avatar
0 votes
0 answers
31 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 ...
user avatar
  • 111
0 votes
0 answers
64 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 ...
user avatar
0 votes
0 answers
32 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 ...
user avatar