Solution number three:
- Store whitelisted domains in
mapping (string => bool) whitelisted - Find out if a given
domainis whitelisted, usingif (whitelisted[domain])
GitHub
github.com › Arachnid › solidity-stringutils
GitHub - Arachnid/solidity-stringutils: Basic string utilities for Solidity · GitHub
Returns True if self contains needle. ... Returns True if needle is found in self, false otherwise. Returns a newly allocated string containing the concatenation of self and other.
Starred by 1.2K users
Forked by 374 users
Languages Solidity 99.7% | Makefile 0.3%
Top answer 1 of 2
4
modifier contains (string memory what, string memory where) {
bytes memory whatBytes = bytes (what);
bytes memory whereBytes = bytes (where);
require(whereBytes.length >= whatBytes.length);
bool found = false;
for (uint i = 0; i <= whereBytes.length - whatBytes.length; i++) {
bool flag = true;
for (uint j = 0; j < whatBytes.length; j++)
if (whereBytes [i + j] != whatBytes [j]) {
flag = false;
break;
}
if (flag) {
found = true;
break;
}
}
require (found);
_;
}
function foo (string memory str) public contains ("solidity", str) {
...
}
2 of 2
1
This repository include a function that find a word into a string and the number of repetitions.
https://github.com/HermesAteneo/solidity-repeated-word-in-string
Hope it helps
GitHub
github.com › wx7063 › solidity-strings
GitHub - wx7063/solidity-strings: solidity string function: join, contains, find, replace, remove, concat
solidity string function: join, contains, find, replace, remove, concat - GitHub - wx7063/solidity-strings: solidity string function: join, contains, find, replace, remove, concat
Author wx7063
TutorialsPoint
tutorialspoint.com › solidity › solidity_strings.htm
Solidity - Strings
In above example, "test" is a string literal and data is a string variable. More preferred way is to use byte types instead of String as string operation requires more gas as compared to byte operation. Solidity provides inbuilt conversion between bytes to string and vice versa.
GitHub
github.com › Arachnid › solidity-stringutils › blob › master › src › strings.sol
solidity-stringutils/src/strings.sol at master · Arachnid/solidity-stringutils
* modifying s to only contain the remainder of the string after the '.'. * In situations where you do not want to modify the original slice, you · * can make a copy first with `.copy()`, for example: * `s.copy().split(".")`. Try and avoid using this idiom in loops; since · * Solidity has no memory management, it will result in allocating many ·
Author Arachnid
Solidity
docs.soliditylang.org › en › v0.5.3 › frequently-asked-questions.html
Frequently Asked Questions — Solidity 0.5.3 documentation
For now, if you want to modify a string (even when you only want to know its length), you should always convert it to a bytes first: pragma solidity >=0.4.0 <0.6.0; contract C { string s; function append(byte c) public { bytes(s).push(c); } function set(uint i, byte c) public { bytes(s)[i] = c; } }
Stack Exchange
ethereum.stackexchange.com › questions › 97394 › check-if-calldata-contains-string
solidity - Check if calldata contains string - Ethereum Stack Exchange
April 17, 2021 - function checker(address _from, uint _value, bytes calldata _data) external{ //HOW to check if _data contains "SOMETHING"? } ... if(string(_data) == ("SOMETHING")){...}; if(string(_data) == ("0x534f4d455448494e470a")){...}; // SOMETHING in hex if(_data == 0x534f4d455448494e470a){...} if(_data == hex"SOMETHING"){...} if(_data == hex"534f4d455448494e470a"){...}
Educative
educative.io › answers › how-to-perform-string-concatenation-in-solidity
How to perform string concatenation in Solidity
As a result, the new string contains all the concatenated data. The testConcatenate function takes two string inputs (first and second), concatenates them using the concatenate function from the Function library, and returns the result as the output.
Solidity
docs.soliditylang.org › en › v0.8.9 › types.html
Types — Solidity 0.8.9 documentation
The function returns a single bytes memory array that contains the contents of the arguments without padding. If you want to use string parameters or other types, you need to convert them to bytes or bytes1/…/bytes32 first. // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.4; contract ...
MLQ.ai
blog.mlq.ai › solidity-programming-strings-bytes-address-types
Solidity Programming: Strings, Bytes, and Address Types
December 15, 2022 - This also means if one contract ... will contain the address of the last point of contact · If we deploy this contract we see that someAdress is 0x0...initially, and if we hit updateSomeAddress it will automatically change to the last address that interacted with the contract: In this article, we discussed key data types in Solidty: strings, bytes, and ...