Hello guys...so i have this very long string that's received via BLE:
"eNJDhJNDJDNkdhdkdndbfjfkfmKjfhffkfghgkgjfhfnnfggkn.dnffbfnfnADJJHhfjkfjfhfnfkkgkkghjfkflflfghghHDJFKFFLFLLLJNGNFJFJFJFNFMFMhfhfmfkfkfmuytoroemndmdlkffhdhdhdhfgffhjkdhfhfhfhkjdhhfhfhfhfjfhjdjkdjhshshsndhfhfhfh.fhehehehenahhhfghehYywyeddhdnYyYyyyyuwenensmsWIEENDBDBDNDNDNDDHDHDHHSHNSSHjdjhdhdhdhdTEYEDBDBDNNNndbdbdndmddjhdhddqwpromfGEHEHENShyehdndjahshssnsmauyhdndndmdkanhssnsnsmamahdjhdHDHIDOIDMDNDodudnfmfkfjfhsnndjjfnfndnHDJDJHFJnfnfnfmfmfmfmmmmmmmmshdhdnnsbshfhfndnNFFHDHFNFHIEUEEWNDJhfdndndndndbdhdhdhdndndhdndnHDJHDJDHDSNDNDJhdhfjjfjfjfjfjfjfffhfhfhfjfjfjfhhnsjdjfjfhfhfjhjsjdjjdjjGDDHJHGFHFHjhfjfjfjfjeyieifmclvvnvnfifporirudndndhysudududhdb_dbHDHDFHDMNHjfuuejrnfnfkkfjfjfjdjfufufmJFHFUFIFRNRFNFHFUIIFJFHDHRUFFKFJJJFHFHFUFUFJFFNFJEIRURJFJFNFJFJjhh-fjfkfkfnfrurjddhfjfjfnfbnfhuiurrHHJDJFYRIIENFFNFKKDOOFJUJHFhfhfhsudidkfnffjifjfnfhuriffnfnffhfhffnfnfnfnfnnWIRIJFhdhfnffkffjfufukdjhcfhfudhdffhfjfjHFUFNBFFUDJNSDHFUFJFNFNFNHYFHFHFNFNJHyrurnffjfjfhfgfufhfffGhhjhfjjjGhdffffGhhfhfhHFHFHFJhfyruridndnfnfnfhrhNhjhHjhfhfhfhhffufdhjduYRYRRHFHFJHhhfhfnfufufiririrjrnfnfjfijufhfhfhfh"
But i need it to be formatted in a way to make it useful exactly like below:
"eNJDhJNDJDNkdhdkdndbfjfkfmKjfhffkfgh"
"gkgjfhfnnfggkn."
"dnffbfnfnADJJHhfjkfjfhfnfkkgkkghjfkf"
"lflfghghHDJFKFFLFLLLJNGNFJFJFJFNFMFM"
"hfhfmfkfkfmuytoroemndmdlkffhdhdhdhfg"
"ffhjkdhfhfhfhkjdhhfhfhfhfjfhjdjkdjhs"
"hshsndhfhfhfh."
"fhehehehenahhhfghehYywyeddhdnYyYyyyy"
"uwenensmsWIEENDBDBDNDNDNDDHDHDHHSHNS"
"SHjdjhdhdhdhdTEYEDBDBDNNNndbdbdndmdd"
"jhdhddqwpromfGEHEHENShyehdndjahshssn"
"smauyhdndndmdkanhssnsnsmamahdjhdHDHI"
"DOIDMDNDodudnfmfkfjfhsnndjjfnfndnHDJ"
"DJHFJnfnfnfmfmfmfmmmmmmmmshdhdnnsbsh"
"fhfndnNFFHDHFNFHIEUEEWNDJhfdndndndnd"
"bdhdhdhdndndhdndnHDJHDJDHDSNDNDJhdhf"
"jjfjfjfjfjfjfffhfhfhfjfjfjfhhnsjdjfj"
"fhfhfjhjsjdjjdjjGDDHJHGFHFHjhfjfjfjf"
"jeyieifmclvvnvnfifporirudndndhysudud"
"udhdb_"
"dbHDHDFHDMNHjfuuejrnfnfkkfjfjfjdjfuf"
"ufmJFHFUFIFRNRFNFHFUIIFJFHDHRUFFKFJJ"
"JFHFHFUFUFJFFNFJEIRURJFJFNFJFJjhh-"
"fjfkfkfnfrurjddhfjfjfnfbnfhuiurrHHJD"
"JFYRIIENFFNFKKDOOFJUJHFhfhfhsudidkfn"
"ffjifjfnfhuriffnfnffhfhffnfnfnfnfnnW"
"IRIJFhdhfnffkffjfufukdjhcfhfudhdffhf"
"jfjHFUFNBFFUDJNSDHFUFJFNFNFNHYFHFHFN"
"FNJHyrurnffjfjfhfgfufhfffGhhjhfjjjGh"
"dffffGhhfhfhHFHFHFJhfyruridndnfnfnfh"
"rhNhjhHjhfhfhfhhffufdhjduYRYRRHFHFJH"
"hhfhfnfufufiririrjrnfnfjfijufhfhfhfh"
How do i go about it?
For clarity is it a String (an object of the String library) or a string (a zero terminated array of chars) ?
Are there any rules that can be applied to the revised format such as number of characters per line ?
I believe its a string object. Also by my observation, i noticed the rule is 36 characters per line. But in addition, a new line forms after any special characters like a dot, underscore or a dash. Then each line is appended with a double quote at the front and back.
Is that really the case or are the double quotes simply presented for the benefit of us humans?
Right, maybe that's the case....can you help?
It is vital that you know what type of data it is. Where does it come from ? Please post the sketch that reads it
wal0ck2023:
can you help?
Not without more detail
Why the need for that exact output format ? What are you doing with the output ?
That long string is received via BLE like so;
class CharacteristicCallBack: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pChar) override {
std::string rxValue = pChar -> getValue();
if (rxValue.length() > 0) {
value = "";
for (int i = 0; i < rxValue.length(); i++){
value = value + rxValue[i];
}
value_return = value_return + value;
}
Serial.println(value);
But i need the content of "value" i.e the very long string to be formatted in a certain way like i described before.
wal0ck2023:
like i described before.
I cannot see a description of the required format, just an example. You mention 36 characters per line and special characters causing a linefeed, but nothing definitive. It is also not clear whether the quotation marks at each end should be included in the output or not
The required format is in the first part of this post...can you please check so i dont keep reposting...thanks
Here's what i have;
"eNJDhJNDJDNkdhdkdndbfjfkfmKjfhffkfghgkgjfhfnnfggkn.dnffbfnfnADJJHhfjkfjfhfnfkkgkkghjfkflflfghghHDJFKFFLFLLLJNGNFJFJFJFNFMFMhfhfmfkfkfmuytoroemndmdlkffhdhdhdhfgffhjkdhfhfhfhkjdhhfhfhfhfjfhjdjkdjhshshsndhfhfhfh.fhehehehenahhhfghehYywyeddhdnYyYyyyyuwenensmsWIEENDBDBDNDNDNDDHDHDHHSHNSSHjdjhdhdhdhdTEYEDBDBDNNNndbdbdndmddjhdhddqwpromfGEHEHENShyehdndjahshssnsmauyhdndndmdkanhssnsnsmamahdjhdHDHIDOIDMDNDodudnfmfkfjfhsnndjjfnfndnHDJDJHFJnfnfnfmfmfmfmmmmmmmmshdhdnnsbshfhfndnNFFHDHFNFHIEUEEWNDJhfdndndndndbdhdhdhdndndhdndnHDJHDJDHDSNDNDJhdhfjjfjfjfjfjfjfffhfhfhfjfjfjfhhnsjdjfjfhfhfjhjsjdjjdjjGDDHJHGFHFHjhfjfjfjfjeyieifmclvvnvnfifporirudndndhysudududhdb_dbHDHDFHDMNHjfuuejrnfnfkkfjfjfjdjfufufmJFHFUFIFRNRFNFHFUIIFJFHDHRUFFKFJJJFHFHFUFUFJFFNFJEIRURJFJFNFJFJjhh-fjfkfkfnfrurjddhfjfjfnfbnfhuiurrHHJDJFYRIIENFFNFKKDOOFJUJHFhfhfhsudidkfnffjifjfnfhuriffnfnffhfhffnfnfnfnfnnWIRIJFhdhfnffkffjfufukdjhcfhfudhdffhfjfjHFUFNBFFUDJNSDHFUFJFNFNFNHYFHFHFNFNJHyrurnffjfjfhfgfufhfffGhhjhfjjjGhdffffGhhfhfhHFHFHFJhfyruridndnfnfnfhrhNhjhHjhfhfhfhhffufdhjduYRYRRHFHFJHhhfhfnfufufiririrjrnfnfjfijufhfhfhfh"
Below is the required format;
"eNJDhJNDJDNkdhdkdndbfjfkfmKjfhffkfgh"
"gkgjfhfnnfggkn."
"dnffbfnfnADJJHhfjkfjfhfnfkkgkkghjfkf"
"lflfghghHDJFKFFLFLLLJNGNFJFJFJFNFMFM"
"hfhfmfkfkfmuytoroemndmdlkffhdhdhdhfg"
"ffhjkdhfhfhfhkjdhhfhfhfhfjfhjdjkdjhs"
"hshsndhfhfhfh."
"fhehehehenahhhfghehYywyeddhdnYyYyyyy"
"uwenensmsWIEENDBDBDNDNDNDDHDHDHHSHNS"
"SHjdjhdhdhdhdTEYEDBDBDNNNndbdbdndmdd"
"jhdhddqwpromfGEHEHENShyehdndjahshssn"
"smauyhdndndmdkanhssnsnsmamahdjhdHDHI"
"DOIDMDNDodudnfmfkfjfhsnndjjfnfndnHDJ"
"DJHFJnfnfnfmfmfmfmmmmmmmmshdhdnnsbsh"
"fhfndnNFFHDHFNFHIEUEEWNDJhfdndndndnd"
"bdhdhdhdndndhdndnHDJHDJDHDSNDNDJhdhf"
"jjfjfjfjfjfjfffhfhfhfjfjfjfhhnsjdjfj"
"fhfhfjhjsjdjjdjjGDDHJHGFHFHjhfjfjfjf"
"jeyieifmclvvnvnfifporirudndndhysudud"
"udhdb_"
"dbHDHDFHDMNHjfuuejrnfnfkkfjfjfjdjfuf"
"ufmJFHFUFIFRNRFNFHFUIIFJFHDHRUFFKFJJ"
"JFHFHFUFUFJFFNFJEIRURJFJFNFJFJjhh-"
"fjfkfkfnfrurjddhfjfjfnfbnfhuiurrHHJD"
"JFYRIIENFFNFKKDOOFJUJHFhfhfhsudidkfn"
"ffjifjfnfhuriffnfnffhfhffnfnfnfnfnnW"
"IRIJFhdhfnffkffjfufukdjhcfhfudhdffhf"
"jfjHFUFNBFFUDJNSDHFUFJFNFNFNHYFHFHFN"
"FNJHyrurnffjfjfhfgfufhfffGhhjhfjjjGh"
"dffffGhhfhfhHFHFHFJhfyruridndnfnfnfh"
"rhNhjhHjhfhfhfhhffufdhjduYRYRRHFHFJH"
"hhfhfnfufufiririrjrnfnfjfijufhfhfhfh"
Does it make sense now?
Do you have a list of these special characters?
wal0ck2023:
Does it make sense now?
Repeating the same example doesn't help. Are those the only 3 special characters that terminate a set of characters.
What is the maximum number of rows?
Which Arduino are you developing this for?
There's no max number of rows
Yes only those 3 special characters are being considered. I'm developing for an ESP32. That long string is a token so the length doesnt matter. what matters is the string comes in, gets formatted into 36 characters per row/line, if there's a special character, use it as a line feed. Thats it.
I guess a fixed size array of rows of 36 chars is out then.
It's rather inviting disaster to say that there is no maximum as even an ESP32 has a finite amount of RAM, even if it is vast compared to an UNO.
Is your intention to receive all the chars and then process them, or do it on the fly?
What will you do with this data after processing? How will it be accessed once processed?
1 Like
Ok thanks. What i am actually trying to do is base64 conversion. But the string is too long such that when i try converting, it prints garbage. But i realized that (i tried with the same string stored in my mode as a constant) formatting the same string into several rows of 36 characters each as described earlier is what works fine. For the token size, i'm sure there's a limit too. I want this string formatted then parsed into base64 decoding. I hope thats a little bit clear now.
Arduino IDE confirms the string is too long and formatted it this way;
"eNJDhJNDJDNkdhdkdndbfjfkfmKjfhffkfgh"
"gkgjfhfnnfggkn."
"dnffbfnfnADJJHhfjkfjfhfnfkkgkkghjfkf"
"lflfghghHDJFKFFLFLLLJNGNFJFJFJFNFMFM"
"hfhfmfkfkfmuytoroemndmdlkffhdhdhdhfg"
"ffhjkdhfhfhfhkjdhhfhfhfhfjfhjdjkdjhs"
"hshsndhfhfhfh."
"fhehehehenahhhfghehYywyeddhdnYyYyyyy"
"uwenensmsWIEENDBDBDNDNDNDDHDHDHHSHNS"
"SHjdjhdhdhdhdTEYEDBDBDNNNndbdbdndmdd"
"jhdhddqwpromfGEHEHENShyehdndjahshssn"
"smauyhdndndmdkanhssnsnsmamahdjhdHDHI"
"DOIDMDNDodudnfmfkfjfhsnndjjfnfndnHDJ"
"DJHFJnfnfnfmfmfmfmmmmmmmmshdhdnnsbsh"
"fhfndnNFFHDHFNFHIEUEEWNDJhfdndndndnd"
"bdhdhdhdndndhdndnHDJHDJDHDSNDNDJhdhf"
"jjfjfjfjfjfjfffhfhfhfjfjfjfhhnsjdjfj"
"fhfhfjhjsjdjjdjjGDDHJHGFHFHjhfjfjfjf"
"jeyieifmclvvnvnfifporirudndndhysudud"
"udhdb_"
"dbHDHDFHDMNHjfuuejrnfnfkkfjfjfjdjfuf"
"ufmJFHFUFIFRNRFNFHFUIIFJFHDHRUFFKFJJ"
"JFHFHFUFUFJFFNFJEIRURJFJFNFJFJjhh-"
"fjfkfkfnfrurjddhfjfjfnfbnfhuiurrHHJD"
"JFYRIIENFFNFKKDOOFJUJHFhfhfhsudidkfn"
"ffjifjfnfhuriffnfnffhfhffnfnfnfnfnnW"
"IRIJFhdhfnffkffjfufukdjhcfhfudhdffhf"
"jfjHFUFNBFFUDJNSDHFUFJFNFNFNHYFHFHFN"
"FNJHyrurnffjfjfhfgfufhfffGhhjhfjjjGh"
"dffffGhhfhfhHFHFHFJhfyruridndnfnfnfh"
"rhNhjhHjhfhfhfhhffufdhjduYRYRRHFHFJH"
"hhfhfnfufufiririrjrnfnfjfijufhfhfhfh"
So i think if i could achieve the same format, then base64 conversion should work just fine.
Simple have a variable for character count, and check each character for special characters.
Some sample code.
If (charCount == 36 or charArray[charCount] == '.') {// then split with line feed.}
Thanks but am not sure i understand you sample code enough. Can you be more explicit?
Well here is some better code.
if (charCount == 36 or charArray[arrayCount] == '.') {
charCount = 0; // reset the character counter
formattedString += 10; // line feed
} else {
formattedString += charArray[arrayCount];
charCount++;
}
arrayCount++;
1 Like
Ok so what does this do? Sorry i just need to understand it and is there an "or" in c++?