How to remove leading & trailing white spaces within a column range? - range

How to remove leading & trailing white spaces within a column range?
This doesn't work:
9s/\%>11c\%<40c^\(\s\+\)//e
9s/\%>11c\%<40c\(\s\+\)$//e

""""""""""""""""""""""""""""""""""""""""""""""""
" Delete Leading White Spaces
""""""""""""""""""""""""""""""""""""""""""""""""
function <SID>OxnzDeleteLeadingSpacesFunc()
try
:%s/^\s\+//
catch /^Vim\%((\a\+)\)\=:E486/
echo "No more leading space exists"
endtry
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""
" Delete Trailing White Spaces
""""""""""""""""""""""""""""""""""""""""""""""""
function <SID>OxnzDeleteTrailingSpacesFunc()
try
:%s/\s\+$//
catch /^Vim\%((\a\+)\)\=:E486/
echo "No more trailing space exists"
endtry
endfunction

Related

How to trim leading and trailing spaces from a string in flutter

I have a 'textformfeild' that takes strings and I want to trim the white spaces at the begining and the end and strict the one in the middle to only one space.
for example if my string is like this:(....AB....CD.....) where the black dots represent the white spaces.
and I wanna make it look like this:(AB.CD)
any idea on how to do that?
this is what I tried to do:
userWeight!.trim()
but this will remove all the white spaces including the one in the middle
trim will remove left and right spaces. You can use RegExp to remove inner spaces:
void main(List<String> args) {
String data = " AB CD ";
String result = data.trim().replaceAll(RegExp(r' \s+'), ' ');
print(result); //AB CD
}
Trim - If you use trim() this will remove only first and end of the white spaces example,
String str1 = " Hello World ";
print(str1.trim());
The output will be only = Hello World
For your purpose you may use replaceAll
String str1 = "....AB....CD.....";
print(str1.replaceAll("....","."));
The output will be = ".AB.CD."
If you still want to remove first and last . use substring
String str1 = "....AB....CD.....";
print(str1.replaceAll("....",".").substring( 1, str1.length() - 1 ));
The output will be = "AB.CD"
This is what your expected output is.
Trim will remove white spaces before and after the string..
Trim will only remove the leading and trailing spaces or white space characters of a given string
Refer this for more:
https://api.flutter.dev/flutter/dart-core/String/trim.html
String str = " AB CD ";
str = str.trim();
while (str.contains(" ")) {
str = str.replaceAll(" ", " ");
}
print(str);

I need to remove an character between two parenthesis

As the title suggests, I need to remove an character between two characters along a string.
E.g. I want to remove the semicolon between two parenthesis
<>word (word ; word) word<>
output desidered:
<>(word word)<>
Your description and the desired output do not match!
To remove the semicolon between two brackets you can use
sed '/([^)]*/s/;//'
example
echo "<>word (word ; word) word<>" | sed '/([^)]*/s/;//'
output
<>word (word word) word<>

iText PDFSweep RegexBasedCleanupStrategy not work in some case

I'm trying to use iText PDFSweep RegexBasedCleanupStrategy to redact some words from pdf, however I only want to redact the word but not appear in other word, eg.
I want to redact "al" as single word, but I don't want to redact the "al" in "mineral".
So I add the word boundary("\b") in the Regex as parameter to RegexBasedCleanupStrategy,
new RegexBasedCleanupStrategy("\\bal\\b")
however the pdfAutoSweep.cleanUp not work if the word is at the end of line.
In short
The cause of this issue is that the routine that flattens the extracted text chunks into a single String for applying the regular expression does not insert any indicator for a line break. Thus, in that String the last letter from one line is immediately followed by the first letter of the next which hides the word boundary. One can fix the behavior by adding an appropriate character to the String in case of a line break.
The problematic code
The routine that flattens the extracted text chunks into a single String is CharacterRenderInfo.mapString(List<CharacterRenderInfo>) in the package com.itextpdf.kernel.pdf.canvas.parser.listener. In case of a merely horizontal gap this routine inserts a space character but in case of a vertical offset, i.e. a line break, it adds nothing extra to the StringBuilder in which the String representation is generated:
if (chunk.sameLine(lastChunk)) {
// we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
if (chunk.getLocation().isAtWordBoundary(lastChunk.getLocation()) && !chunk.getText().startsWith(" ") && !chunk.getText().endsWith(" ")) {
sb.append(' ');
}
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
} else {
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
}
A possible fix
One can extend the code above to insert a newline character in case of a line break:
if (chunk.sameLine(lastChunk)) {
// we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
if (chunk.getLocation().isAtWordBoundary(lastChunk.getLocation()) && !chunk.getText().startsWith(" ") && !chunk.getText().endsWith(" ")) {
sb.append(' ');
}
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
} else {
sb.append('\n');
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
}
This CharacterRenderInfo.mapString method is only called from the RegexBasedLocationExtractionStrategy method getResultantLocations() (package com.itextpdf.kernel.pdf.canvas.parser.listener), and only for the task mentioned, i.e. applying the regular expression in question. Thus, enabling it to properly allow recognition of word boundaries should not break anything but indeed should be considered a fix.
One merely might consider adding a different character for a line break, e.g. a plain space ' ' if one does not want to treat vertical gaps any different than horizontal ones. For a general fix one might, therefore, consider making this character a settable property of the strategy.
Versions
I tested with iText 7.1.4-SNAPSHOT and PDFSweep 2.0.3-SNAPSHOT.

Access, How can I change lowercase letter of first letter in last name to uppercase

I would like to change lowercase letter of first letter in last name to uppercase by using code
my code from form is :
Option Compare Database
Private Sub Text19_Click()
Text19 = UCase(Text19)
End Sub
but there is no change to my table!
Furthermore, how can I find last name with a space, comma or period and make it without a space, comma and period.
such as
Moon,
Moon.
[space] Moon
change them to just
Moon
If there is no change to your table, maybe your field is not bound to the recordset? Maybe you need to 'Refresh' your form.
Also, it looks like you are trying to use this code on a TextBox?
Code would be as follows:
Private Sub Text19_DblClick(Cancel As Integer)
Text19 = Trim(Text19) ' Get rid of leading and trailing spaces.
If right(Text19, 1) = "." Or right(Text19, 1) = "," Then ' Remove comma, period
Text19 = left(Text19, Len(Text19) - 1)
End If
Text19 = UCase(left(Text19, 1)) & Mid(Text19, 2)
End Sub

Getting the cursor context in Dragon NaturallySpeaking's advanced scripting

I wonder whether it is possible to get the cursor context in Dragon NaturallySpeaking's advanced scripting.
By cursor context, I mean the surrounding characters. For example, I sometimes want to condition some steps of a voice command on whether the character preceding the cursor is a space.
Best I could come up with is my CheckNewPara function shown here: http://knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=2739&discTab=true&messid=11427&parentid=11409&FTVAR_FORUMVIEWTMP=Single
Function CheckNewPara()
Clipboard$()
SendKeys "+{Left}^c", True ' copy previous character
Select Case Clipboard$()
Case "" ' if the prior character is nothing
CheckNewPara = "" ' add no space
Case Chr(13)&Chr(10), Chr(9), ")" ' if the prior character is a Lf-CR, tab or )
SendKeys "{Right}", True
CheckNewPara = "" ' add no space
Case "." ' if the prior character is a period
SendKeys "{Right}", True
Clipboard$() ' check for No.
SendKeys "+{Left 3}^c", True ' copy prior three characters
SendKeys "{Right}", True
If Clipboard$() = "No." Then
CheckNewPara = " " ' add one space after No.
Else
CheckNewPara = " " ' add two spaces after period
End If
Case "?", "!"
SendKeys "{Right}", True
CheckNewPara = " " ' add two spaces after other ends of sentence
Case Else
SendKeys "{Right}", True
CheckNewPara = " " ' add one space in the usual case
End Select
Clipboard$()
End Function
You should look at the complete topic at http://knowbrainer.com/forums/forum/messageview.cfm?FTVAR_FORUMVIEWTMP=Linear&catid=4&threadid=2739&discTab=true to get all the context, but the code in the post I pointed to should get you started.
My newest version of the function actually calls an AutoHotKey script which looks at both the prior three characters (or as many as there are, if there are any) and the next two characters (or how ever many there are, if there are any) and returns either a space, two spaces, or nothing depending on the context. The context could be a terminal punctuation (requiring two spaces) or a pound/hash # symbol or close paren bracket or brace ) ] } all requiring no spaces, or else by default one space. I also have it so I can call it before and/or after typing in the results of a Dragon command.
HTH, YMMV,