How can I split a string on characters in Visual C++? - string

I have been trying to create a Visual C++ program which takes a string from a text box, then counts the number of characters in it and puts each character in different label. With which functions can I take the string from the text box, split the string on characters and put every character in different label?

Use GetDlgItemText to copy text into char-array or a CString object. If text-control is mapped to a CEdit variable, use GetWindowText to copy text into buffer.
Use strlen or CString::GetLength to find the length of string. If you want to trim spaces, use CString::Trim
Then run a loop starting from 0th index till the length-1. Locate what those characters are, and place them into target controls.

Related

How to make words separate without space in android studio

I have different numbers and calculation signs in a string format text in android studio. I want my numbers show correctly but if I do not put space before signs my numbers are shown separately when text get to end of lines. If I put space, so I will have redundant spaces in my screen. What should I do to have correct shown numbers and not to have redundant spaces?! My program is in Kotlin language.
You can use the triple quote(""") option in Kotlin. It's good for specifying exactly how you want the text to look. This code:
val string = """
Multiple
line string
"""
println(string)
Will show:
Multiple
line string

Is there a way to use the Find and Replace function in Excel to replace the first and last entry in a string of text?

I have a sequence of a letters, in my case part of a gene. I want to change the first and the last letter in this string of text, but keep the internal characters the same.
For example, if I have the the sequence:
ATCGAATCCATGACG
And I want to change the first letter, in this case A to the word START and change the last letter, G, to STOP all while keeping the internal A's and G's the same. Is this possible to do with the Find and Replace function, or will I have to write a script?
It is easy to do when I have a handful of sequences, I do it by hand. When I get into the hundreds, it can be very difficult.
Thank you.
The function LEN(text) returns the number of characters within a string of letters. MID(text, start, num_chars) returns the middle section of a string. CONCATENATE(text1, text2, ...) pieces together different strings. We can use these in combination to get what you want:
=CONCATENATE("START", MID(A1,2,LEN(A1)-2), "STOP")
You could use replace, and focus on the left and right side independently, then combine, or you can use left/right to add string of text to the available string minus a character, like:
="START"&LEFT(RIGHT(A1,LEN(A1)-1),LEN(A1)-2)&"STOP"
I used left/right, but mid would also work
just another option:
=REPLACE(REPLACE(A1,LEN(A1),1,"STOP"),1,1,"START")

Userform Input Small hyphen & Long hyphen? (โœฑUsing symbols in Excel)

I am entering a string in a Userform in Excel-VBA from the user side of the form. I would want to know how to enter the Long Hyphen.
The Small Hyphen would be Shift + - the (the minus sign button next to 0).
How would you enter the Long Hyphen on the form as I am doing a string match in my VBA code on the back-end? It can be entered with Alt+0150, but is there another simpler way?
If the option of entering the Long Hyphen doesn't work then I will handle this value on the back-end through a find and replace method or something in VBA.
๐Ÿ‘† There is only one "Hyphen"... โ€‚โ€‚ It's part of a แ–ดแ—ฉแ—ฐแŽฅแ’ชฦณ แดา“ แ‘•แ•ผแ—ฉแ–‡แ—ฉแ‘•ไธ…แ—ดแ–‡แ”• called Dashes.
Examples:
Hyphen [-] (-)
Minus sign [โˆ’] (โˆ’)
En dash [โ€“] (โ€“)
Em dash [โ€”] (โ€”)
โœฑ Your browser might render them differently, but the fonts above are supposed to be [Consolas or Courier 13px] and (Arial or Helvetica 15px). While they all kind of look the same in this font, those are four different characters.
The characters can be copy/pasted directly from here - โˆ’ โ€“ โ€” into Excel (but not to the the VBA Editor), or can be produced along with 136,686 other Unicode characters, either:
with a worksheet formula, using the แดœษดษชแด„สœแด€ส€ function:
=UNICHAR(9733) 'produces a [โ˜…] star character.
programmatically with VBA, using the ChrW function:
Range("A1") = ChrW(9743) 'puts a wee [โ˜] rotary phone in cell A1.
More about dashes โ€”
What they are
How to use them
"Stealing" Unicode characters from websites
There are all sorts of handy Unicode symbols โ€” so many that it can be hard to find "just" the right one.
However you can (and will!) find other Unicode symbols on web pages that you want to use programmatically. All you need is the symbol's code, which can be determined easily:
Copy/paste the symbol from your browser (being careful to copy only the single character; no spaces, etc.) into a cell in Excel
then, go to VBA's Immediate Window ( AltF11โ†’CtrlG ), type:
MsgBox AscW([a1])
...(Where A1 is the cell with the character). Hit Enter, and the character's Unicode code will display.
You could also use Windows' built-in Character Map utility, or one of many third-party browser plug-ins. You can even paste a symbol directly into Google to learn more about it:
Finally, no discussion on the topic of Unicode would be complete without links to:
โ€‚โ€‚๐Ÿ‘‰ โ€‚The Unicode Consortium (unicode.org) and,
โ€‚โ€‚๐Ÿ‘‰ โ€‚โ€œศถษฆษ› ๐“’๐“ธ๐“ธ๐“ต ๐•ฑ๐–†๐–“๐–ˆ๐–ž โ“‰โ“”โ“งโ“ฃ ๐”พ๐•–๐•Ÿ๐•–๐•ฃ๐•’๐•ฅ๐• ๐•ฃโ€ โ€‚(Yes, those are all plain text characters.)
...and if you're looking for a unique gift, or just want your name to go down in history for something that really matters, you can even adopt a Unicode character, starting at $100 แดœsแด…!
Special thanks to Vinton Cerf for adopting the Unicode Leonard Nimoy's "Live Long and Prosper" symbol.
โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚โ€‚๐Ÿ––

Most efficient way to store a string in bytes?

Say I have a simple bytecode-like file format for saving data.
If I want to store a string, should I do it like in source files where all characters between a certain byte is the string,
or should I first store the length of the string then the string bytes?
Or are both solutions horrible and if so which one can I use?
It depends on whether you want to store:
a single string
a number of strings
different length strings
all the same length
For all of the above, it may also matter if your strings contain:
any characters
only certain characters
formatting
In general, you should use Unicode.
For a single string, you simply can use an entire file to contain the string, the end-of-file will be the same as the end of string. No need to store the length of the string.
If the strings aren't all (around) the same length you can use an inline separator to separate the strings. Often the newline character is useful for this (especially since a lot of programming languages support this way of reading in a file line-by-line), but other markers such as tab are common.
CSV text files often use double quotes to enclose strings that contain commas (or other column separator) (which would otherwise indicate the next column value was starting), or line-breaks (which would otherwise indicate the next row).
Of course, now you have the problem of how to store a double quote in your string.
If you want to store formatting, you can use a markup language (html) or it may be enough to allow for line breaks and/or some markdown.

How can I detect "excessive spaces" in a string?

I'm making a simple android game in Lua, and in one of its steps to set the game is set an word (or sentence; basically, a string) input by the player. The "word" may have spaces, but I want to forbid the player to input a string with two or more spaces in a row, like "fly bird".
I tried using string.match(word, " "), string.match(word, "%s%s")
and string.match(word, "%s+%s+") and none of these worked, and somehow, the last one always "detect" double space, no matter if it has or not spaces.
What can I do to detect if there are multiple spaces in a row in a string? (Just detect, not replace, so I can send a warning message to the player.)
If its exactly two spaces you are interested in, simply use find
word:find(' ')
It will return range of first occurrence of two consecutive spaces.
input = input:gsub("%s+", " ")
The above code should take the input and remove all excessive spacing and replace it with just 1 space.

Resources