controlP5 textfield contents. Processing - textfield

I have a sketch in processing I am working on which contains a textfield and a submit button. When the submit button is pressed, a file with is created using the name given in the textfield. I want to make sure something has been entered into the textfield when the submit button is pressed, however, it appears that by default the string is not empty or contain white space and is not caught by if statements.
Is there any simple way to check that something has been entered in the text field without needing to resort to something like regex?

I am not sure I understood whether by default your string is not empty and also does not contain white space (which would make it an odd example). The best possible check I can think of is to trim whatever the entered string is and then check if it is empty:
if(enteredString.trim().length() > 0) println("The string is valid");
the trim() method trims leading and trailing spaces, so if there are only spaces they will be removed making the string empty. Also, since you are saving files you might want to check for invalid characters. With Processing (Java) you don't necessarily have to resort to regex since you can do stuff like these:
String s = "ashd/ah";
println(s.contains("/"));
println(s.replace("/","-"));
which will print:
true
ashd-ah

Related

Access Macro - Was textbox changed from default value?

I have an Access form with textboxes that contain some default text. The users are required to replace the text with words of their own, so I wrote a macro to confirm that (before proceeding to the next record) the text boxes no longer contain the default text. (It gives user a warning plus some other tasks, which is why I'm not using built-in Validation rules.)
The macro contains this sequence:
SetLocalVar
Name: booDetailDefault
Expression = [Forms]![frmChangeReq]![txtProblem].[Text]=[Forms]![frmChangeReq]![txtProblem].[DefaultValue]
The idea is if ...[Text] is the same as ...[DefaultValue], then booDetailDefault would be TRUE, and if not, FALSE.
However, what I do get is "Type Mismatch". I would think that Text and DefaultValue would be the same type.
Can you tell why I got this error?
Is there any way to display the Text and DefaultValue values so I can see why Access thinks they're different?
Is there a better way to see if the text boxes have been changed?
EDIT: The default text is set in the Property Sheet for the textbox. I've been running it manually, not tying it to an event yet, until I get it working.
I used Text instead of Value because that's what was available in the Macro Builder, but just in case I tried changing it to Value. It works, although I have to tell the expression to expect quotation marks around half of it:
[Forms]![frmChangeReq]![txtProblem].[DefaultValue]="""" & [Forms]![frmChangeReq]![txtProblem].[Value] & """"

How to get data from the CKEditor5's editor without the NBSP filler?

An empty editor's getData() method returns an empty paragraph filled with the . There is a function getDataWithoutFiller() in the API but it's not a function available to use in the editor instance.
Do you want to check whether the editor is empty? There's no such option for now, but it should be implemented in the next iteration. The request for that functionality is in the https://github.com/ckeditor/ckeditor5/issues/401.
The simple but not complete workaround would be to replace and other white spaces with an empty string and check then if there are only empty paragraphs.
Other than that, the in the non-empty content is important as otherwise, the created paragraphs would be 0px high.

Char & behaviour on controls

Currerently I face strange behaviour on my controls when text is present either on advlistbox items or buttonx and probably rest as well. This happens when i use & charackter within string. For instance when i use double && it shows single one. Another example when i put e.g &&&something then it shows &something with s - underscored. Is there anyone whom knows what is going on and how can i avoid that situation?
A double ampersand is used to escape the default behavior of an ampersand relative to controls. When an ampersand precedes control text it underlines the following character, usually to denote that controls hotkey. In the case of your triple ampersand situation you are using the right most ampersand as the underline and the remaining 2 as an escape so that a literal ampersand is displayed in your controls text.
If your goal is to literally display 2 ampersands then you must supply your control text with a total of 4 consecutive ampersands. (&&&&)

How can I disable automatic string detection in VS2015?

I'm using VB.NET, and my code contains a lot of strings that very often have double quotes inside of them. My problem is that as I'm fixing the string to escape double quotes (replacing every '"' with '""' inside of the string) it messes with the proceeding code, temporarily assuming everything is a string (since the double quotes don't match up) and completely messing up the formatting of other strings. It assumes that the start of a following string is the end of the current string which causes the actual string to be interpreted and formatted as code, which I have to go back and fix (since it adds spaces and other formatting characters that shouldn't actually be there).
Is there any way to disable this behavior? I didn't have the same problem in VS2013. I've been looking under Tools > Options > Text Editor > Basic, but I couldn't find anything relevant.
Additional Information: I can just modify the strings in a separate text document to escape all of the double-quotes (which is what I've resorted to for now), but in VS2013 I could easily just copy/paste the strings directly into my code without it messing up proceeding strings by temporarily interpreting them as code due to the uneven count of double-quotes.
This behavior is especially problematic when manually adding double-quotes within strings, because if you don't escape them quickly enough (or make a brief typo when doing so), you get the same issue.
You might notice that for other languages, such as C++, writing a string on one line (even with an uneven number of double-quotes) does not affect proceeding lines. Having this same behavior for VB would be great, assuming that there's some setting to enable it.
Yes its an inconvenience.
What I usually do is put some non-used character (e.g. some unused symbol on keyboard, or Alt+{some number}) instead of double quotes. When I'm done building my string whatever way I want, I just finalize it with either bringing up the Find and Replace box and replace that character with two double-quotes. Or just put a REPLACE statement immediately following it, replacing that character with Chr(34).
Instead use Chr(34), or if you end up repeating strings at all, store them as a resource.

String Manipulation Inconsistency

This is a more general question. I am reading a document and saving its contents into a string variable. The resulting variable contains approximately 1 million characters (no cleansing). My code would then search the string, and extract key words. However, I am hung-up on an issue:
If I pass the string directly to a message box, it will show me the contents using Mid:
Messagebox.Show(Mid(searchString, startPos, endPos))
However, if I first pass the mid to a string variable, the contents are empty and the messagebox displays nothing:
Dim myString as String
myString = Mid(searchString, startPos, endPos)
Messagebox.Show(myString)
The same effect happens when I use .substring and when I use a stringbuilder.
Does anybody know why this is happening? I assume something is happening during assignment, but I am not sure what is lost?
Here is a snippet of code:
searchPos = textString.IndexOf(searchText, searchPos, StringComparison.OrdinalIgnoreCase)
MessageBox.Show(searchPos)
MessageBox.Show(Mid(textString, searchPos, 100))
So, the inconsistency is as such: the length of textString is around 3,700,000 characters. When I find the indexOf, the value returned in the first Messagebox is 455,225. However, if I try to pull out the characters using Mid, the second messagebox is blank.
Also, although it claims to be 3,700,000 characters, if I do a messagebox on textString, I am only shown around 6 characters of what appears to be XML. The file that is being searched is an old .ppt file, and I know I can just work-around it, but I am confused by how the computer can find the indexof my searchText correctly, but then cannot show me anything.
Thoughts?