Convert string to BSTR - visual-c++

From the following function, I use the path. Now I generate some lets say list of names separated by newline
func(BSTR * path)
{
// From path paramter client sent, I use the path.
//Now I generate some lets say list of names separated by newline
string output = "Bob\n Rob \n Lilly \n";
// Now client wants the path to be modified with the output
// So i did the following
SysFreeString(*path);
*path= SysAllocStringByteLen(output.c_str(), output.size());
}
Is the last two lines correct. Somehow testing doesnot seems ok !

Related

How to correctly pass the Cyrillic alphabet in a post request? Groovy

It is not possible to correctly transfer the Cyrillic alphabet to the post request. Letters are replaced with question marks.
Everything works well with numbers and the Latin alphabet.
name = 'иии.docx'
multipartRequestEntity.addPart('filename', new StringBody(name)) // return '???.docx'
name = 'fff.docx'
multipartRequestEntity.addPart('filename', new StringBody(name)) // return 'fff.docx'
How to correctly pass the Cyrillic alphabet in a post request?
Try by create the String with encoding, something like this:
name = new String('иии.docx', 'UTF-8')
Also, verify if the multipartRequestEntity has any method to set the encoding on the output.

Flutter - String check for ellipsis

My flutter apps displays description strings which are fetched from a third party, thus these descriptions may already be fitted with ellipsis as to lead the story onwards but the api only fetches around 7 lines or so of the description.
I want every description to contain an ellipsis but don't want to add ellipsis to strings that already contain them.
I want to turn this
scan the face of each account holder as
into this
scan the face of each account holder as...
but if the original already contains this ellipsis, it should be skipped.
String input = 'your string';
if (!input.endsWith('...')) {
input += '...';
}
Key here is String.endsWith(), it's the easiest way to know if the content already ends with an ellipsis.
Enhanced answered from #greyaurora
be careful trailing space, e.g. my data...
be careful with different ways to display ellipsis, e.g. ... (3 dots ) vs … (1-char ellipsis)
void main() {
String input = 'your string';
String trimmed = input.trim();
if (!trimmed.endsWith('...') && !trimmed.endsWith('…')) {
trimmed += '…';
}
print('hello ${trimmed}');
}

Node.JS - if a string includes some strings with any characters in between

I am testing a string that contains an identifier for which type of device submitted the string. The device type identifier will be something like "123456**FF789000AB" where the * denote any character could be used at this position. I run a series of functions to parse additional data and set variables based on the type of device submitting the data. Currently, I have the following statement:
if (payload[4].includes("02010612FF590080BC")) { function(topic, payload, intpl)};
The string tested in the includes() test will always start with 020106, but the next two characters could be anything. Is there a quick regex I could throw in the includes function, or should I organize the test in a different way?
To match the "020106**FF590080BC" pattern, where * can be anything, you can use RegExp.test() and the regular expression /020106..FF590080BC/:
if (/020106..FF590080BC/.test(payload[4])) { ... }
Also, if you require that the pattern must match the beginning of the string:
if (/^020106..FF590080BC/.test(payload[4])) { ... }

Go how can i efficient split string into parts

i am fighting with a string splitting. I want to split string by wildcards into a slice, but this slice should contain this wildcards as well.
For example: /applications/{name}/tokens/{name} should be split into [/applications/ {name} /tokens/ {name}] etc.
Here is a sample code i wrote, but it is not working correctly, and i don't feel good about it either.
https://play.golang.org/p/VMOsJeaI4l
There are some example routes to be tested. Method splitPath split path into parts and display both: before and after.
Here is a solution:
var validPathRe = regexp.MustCompile("^(/{[[:alpha:]]+}|/[-_.[:alnum:]]+)+$")
var splitPathRe = regexp.MustCompile("({[[:alpha:]]+}|[-_.[:alnum:]]+)")
func splitPath(path string) parts{
var retPaths parts
if !validPathRe.MatchString(path) {
return retPaths
}
retPaths = splitPathRe.FindAllString(path, -1)
return retPaths
}
I made this by creating two regular expressions, one to check if the path was valid or not, the other to extract the various parts of the path and return them. If the path is not valid it will return an empty list. The return of this will look like this:
splitPath("/path/{to}/your/file.txt")
["path" "{to}" "your" "file.txt"]
This doesn't include the '/' character because you already know that all strings in the return but the last string is a directory and the last string is the file name. Because of the validity check you can assume this.

How to get the file name from the full path of the file, in vc++?

I need to get the name of a file from its full path, in vc++. How can I get this? I need only the file name. Can I use Split method to get this? If not how can I get the file name from the full path of the file?
String^ fileName = "C:\\mydir\\myfile.ext";
String^ path = "C:\\mydir\\";
String^ result;
result = Path::GetFileName( fileName );
Console::WriteLine( "GetFileName('{0}') returns '{1}'", fileName, result );
See Path::GetFileName Method
Find the last \ or /1 using one of the standard library string/char * search methods. Then extract the following text. Remember to special case where the / or \ is the last character.
1 The Windows API, for most purposes2 supports both.
1 The exception is when using long paths starting \\?\ to break 260 character limit on paths.
Directory::GetFiles Method (String, String)
Returns the names of files (including their paths) that match the specified search pattern in the specified directory.

Resources