Questions tagged [string]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
31
votes
5answers
27k views

How to convert a bytes32 to string

How can I convert a bytes32 to a string? Does anyone has a magic function or library which does it?
29
votes
4answers
27k views

How to convert a string to bytes32?

How can I convert a string to a bytes32? Does anyone has a magic function or library which does it? For example: This works since as input I gave 32-bits. But it won't work with "> 32-bit" chars. ...
40
votes
5answers
25k views

How to concatenate strings in solidity?

I'm trying to concatenate two strings in solidity. I tried with + or . but neither option works. There is not much documentation on string concatenation yet. Is it even possible? If not, can I ...
19
votes
4answers
21k views

Conversion of uint to string

I am trying to convert uint to string in solidity. Is it possible to convert? if so how can I convert it? Convertion to base 10 is prefered, but in hexadecimal might also be helpful.
37
votes
2answers
29k views

Use string type or bytes32?

What are the benefits to using string datatypes over bytes32 to represent text data. It seems my contract runs into an out of gas exception when I switch the data structures from bytes32 to string.
19
votes
4answers
13k views

Convert address to string

In Solidity, how can I convert the sender address to a string? The comments in How to convert an address to bytes in Solidity? did not provide a working solution
19
votes
2answers
18k views

How can I return multiple strings from a contract function?

In solidity it's obvious how to get a single string returned from a function. But, I'd like to have the smart contract return multiple string values. Is there a way to do this?
13
votes
2answers
4k views

Is it impossible to use an array of strings as the argument to solidity function?

If I try to define a function using an array of strings as an argument, solc gives me the following error: Error: Internal type is not allowed for public or external functions. function test(...
9
votes
2answers
6k views

How to concatenate a bytes32[] array to a string?

I am passing an array of bytes32 to my function. This array can contain numbers or hashes etc. to identify an object. In a new use case I want to pass a URL to this function by splitting the URL into ...
18
votes
2answers
3k views

What is the zero value for a string?

How to verify that a string, or an enum with only string properties, is initialised or not, inside of a mapping? According to the docs, it means checking that the element of the mapping is at its 0-...
18
votes
2answers
5k views

Contract reading a string returned by another contract

I have 2 contracts, Parents and Child which has a public string variable - name. contract Child { string public name; function child (string _name){ name = _name; } } Parents ...
12
votes
6answers
7k views

How to convert string to int

How do i convert a string into a int? here is my code: pragma solidity ^0.4.6; contract MyContract { string public a; /* Constructor */ function MyContract() { a = "0....
30
votes
2answers
9k views

Why do Solidity examples use bytes32 type instead of string?

In many Solidity examples I read that use strings for parameters or return values, I see they are typed as bytes32 although there's a string type. What is the real reason for that? Thanks.
8
votes
2answers
3k views

Clarification of “256 bit word” semantics

EVM has "256bit words". Some cases treat strings shorter than 32 bytes (256 bits) as left-justified ascii (packed into the most significant bytes of the word). Does this mean that the word value of ...
3
votes
1answer
3k views

Solidity convert hex string to bytes

I try to convert hex string to bytes. function MyContract() public { string memory str = "A76A95918C39eE40d4a43CFAF19C35050E32E271"; array1 = bytes(str); bytes memory str1 = hex"...
3
votes
1answer
792 views

Simplest way to use a variable in an Oraclize query?

I have a variable number in my Solidity contract which changes and I need to incorporate this into an oraclize query. My oraclize query looks like the following: oraclize_query(60, "URL", "json(https:...
13
votes
2answers
6k views

Convert with JS a Solidity bytes32 to a Solidity string

I have functions which are forced to return a bytes32 object, but then in my webapp I need to reconvert them to a classic string. How can I do that?
9
votes
3answers
8k views

Is it possible to check string variable's length inside the contract?

I want to sent a string as an argument to a function. But some user may enter maybe 100 size string or even larger. [Q] Inside the function is it possible to check the size of the string and return ...
10
votes
2answers
4k views

Solidity concatenate uint into a string?

How would I concatenate an integer into a string using solidity? For instance, say I have the following: uint myInteger = 12 How can I create the following string "My integer is: 12" with 12 being ...
13
votes
1answer
9k views

How can you check if a `string` is empty in Solidity [duplicate]

How can you check if a type string is empty in Solidity? For instance this would work when testing if a string was initialized to have no characters: string public emptyStringTest = ''; or when you ...
3
votes
1answer
467 views

How to explain string serialization when invoking contract method?

On Ropsten testnet I have deployed a contract like this: // creation of contract object var aContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"...
8
votes
1answer
10k views

How to get string from hex on Smart Contracts results [duplicate]

On a Smart Contract called "mem" there is a function called "get()" that returns a bytes32 that is supposed to be a string. How can I decode the string? The result is an hex value. I have tried ...
4
votes
1answer
6k views

How to convert a string to bytes32 array?

I have known how to convert a string to bytes32. But if the string length is longer than 32, the rest of the string will be truncated. So how to convert a string to bytes32[] array?
2
votes
2answers
468 views

blockHash compression problem inside a contract, block.blockhash(blockNumber) returns “0x” or random hash value

Related to following answer: function block_hash_validation(uint blockNumber, bytes32 blockHash) constant returns(bool isValid) { return (block.blockhash(blockNumber) == blockHash); } When ...
2
votes
2answers
1k views

How to put a variable inside a string in solidity

Does anyone know how to do this, I want to put a variable inside a string: currently using: oraclizeID = oraclize_query("URL","json(https://opensky-network.org/api/states/all?icao24=a4dad4).states[...
1
vote
1answer
215 views

Alternative for String type in smart contract and Solidity?

Regarding the fact using String in contract is expensive, is there any alternative type in Solidity ? The input value (Payload) I want to set is as follows : {"SQN":4,"Node_ID":"...
0
votes
2answers
561 views

Why is string getter returning an empty response?

This is a sequence of another question I asked. I have the following contract contract User { string publicKey; function setPublicKey(string _publicKey) onlyOwner { ...