I have a string like 3ZwgC3xOuq1LpbL4Ajs5. I want to create a function that take that string and convert like 3DV3A2 etc. It will shorten the string and likewise give me the previous string when I export the shortened string.
I am using Dart btw.
3ZwgC3xOuq1LpbL4Ajs5 -------- CONVERT TO --------> 3DV3A2
3DV3A2 -------- CONVERT TO --------> 3ZwgC3xOuq1LpbL4Ajs5
It is impossible to write a function that will compress every string. At best you can write a function that will compress most, but not all, strings.
Compression works by reducing redundancy at some level. Your example string does not appear to have a lot of redundancy, so is probably not very compressible.
Related
Struggling with a really simple problem; I need to convert attribute from string to numeric in FME. have tried using the arithmetic editor, but every time I export to GIS I get string. It seems when one uses the statistics calculator you get numeric.
Any ideas? As I am all out of them.
Ashton
When I call json.decode on financial data returned from a server, I would like to either convert my numerics to decimal (pub.dev package) (or even leave them as strings so I can manually do that later). Everything else I would like to be converted as normal
There's a reviver callback which is passed to _parseJson(), but I can't find the implementation of this external function to study.
Update:
Looks like reviver() is too late: basic conversion has already happened by here and doubles get passed in. Is there any alternative callback that can be used?
I'd use the jsontool package (disclaimer: I wrote it, so obviously that's what I'd turn to first).
It's a low-level JSON processor which allows you (and requires you) to take control of the processing.
It has an example where it parses numbers into BigInts. You could probably adapt that to use Decimal instead.
Languages like Java, let you concatenate Strings using '+" operator.
But as strings are immutable, they advise one to use StringBuilder for efficiency if one is going to repeatedly concatenate a string.
What is the most efficient way to concatenate Strings in Dart ?
https://api.dart.dev/stable/2.9.1/dart-core/StringBuffer-class.html
StringBuffer can be used for concatenating strings efficiently.
Allows for the incremental building of a string using write*() methods. The strings are concatenated to a single string only when toString is called.
It appears that if one uses StringBuffer, one is postponing the performance hit till toString is called?
There are a number of ways to concatenate strings:
String.operator +: string1 + string2. This is the most straightforward. However, if you need to concatenate a lot of strings, using + repeatedly will create a lot of temporary objects, which is inefficient. (Also note that unlike other concatenation methods, + will throw an exception if either argument is null.)
String interpolation: '$string1$string2'. If you need to concatenate a fixed number of strings that are known in advance (such that you can use a single interpolating string), I would expect this to be reasonably efficient. If you need to incrementally build a string, however, this would have the same inefficiency as +.
StringBuffer. This is efficient if you need to concatenate a lot of strings.
Iterable.join: [string1, string2].join(). This internally uses a StringBuffer so would be equivalent.
If you need to concatenate a small, fixed number of strings, I would use string interpolation. It's usually more readable than using +, especially if there are string literals involved. Using StringBuffer in such cases would add some unnecessary overhead.
Here is what I understood:
It appears that performance will vary depending on your use case. If you use StringBuffer, and intend to concatenate a very large string, then as the concatenation occurs only when you call toString, it is at that point where you get the "performance hit".
But if you use "+", then each time you call "+" there is a performance hit. As strings are immutable, each time you concatenate two strings you are creating a new object which needs to be garbage collected.
Hence the answer seems to be to test for your situation, and determine which option makes sense.
I am currently working on Swift script that allows type-checks by compiler for localization strings, something that was sorely needed for a long time. If you are interested, you can check the project on GitHub to get better understanding.
The problem
Part of it is creation of methods from strings, when parser encounters special characters, that are meant to be changed in runtime (%d, %f, %# etc.). String like this:
"PROFILE_INFO" = "I am %#, I am %d years old and %.2fm in height!"
Will get converted to method with following signature:
func profileInfo(value1 : String, value2 : Int, value3 : Float { ...
What I am really curious about and what I could not find anywhere, not even in documentation, is what types are allowed in localization strings. I suspect it goes through default format and there is a lot of types to cover, in which case, I am curious what people used and what types can be omitted. I am using following regexp matching to find the special characters currently, and then converting them to appropriate data types:
let regexp = "%([0-9]*.[0-9]*(d|f|ld)|#|d)"
let matches = self.matchesForRegexInText("%([0-9]*.[0-9]*(d|f|ld)|#|d)", text: string)
I know this covers most of the usual cases, but obviously, I would like to have full coverage if possible.
TLDR:
Q1: What format specifiers are allowed in localization strings - are there any changes from classic string format or everything is the same?
Q2: Is there any better way to convert those characters to appropriate data type than using regexp to parse them out?
Thanks!
In my application i am binding a integer to a gridview column.
Scenario : In the cell edit mode of gridview, if the user types some string values like A+,A. i want text to convert it automatically to integer value.
I am having a collection where each string value will be having a integer assigned.
In the converter i want to check for that and show its corresponding integer value.
Can it be done using IValueConverter
Yes, it makes sense to do this in a value converter.
Out-of-the-box, .NET does not provide any classes or methods for parsing the expression into its numerical equivalent, but you should be able to use numerical parsing libraries like for example NCalc or Simple Math Parser to "do the job" for you.
I honestly don't know if these libraries are immediately available for Silverlight, but if not it is probably worth the effort to port them to SL yourself, rather than writing your own math parser.