xamarin forms Properties/Preferences max recommended string length - xamarin

In the docs for properties/xamarin.essentials preferences they mention to not store "large text". I'm wondering what is considered "large text".
I want to know how big of a class is safe/performant to serialize as json.

so it seems anything more than a few kb should be written to a file

Related

BotComposer, how to iterate through the characters of a string using lg language?

We need to extract a number from a phrase. For example:
"hey, 1234" -> "1234"
"ok, 4567" -> "4567"
"b3456f" -> "3456"
But we don't found how to iterate through a string using only language generator of the Bot Composer.
We try things like:
join(foreach(createArray("ab c"), x, concat(x, '-')), '')
But with no result... is there any prebuild function that converts a simple string on an array of chars, so we can iterate char by char using foreach?
Thanks!
As far as I know, this currently isn't possible as there's no way to iterate over a string or split a string into a new array by character. I've opened a GitHub issue to request it as an enhancement.
For:
"hey, 1234" -> "1234"
"ok, 4567" -> "4567"
You can use split().
Unfortunately, you're out of luck for your "b3456f" -> "3456" example, unless you know it's going to come in that exact format, in which case, you could use substring().
You could maybe look into using a Regex to do this, if you know the formats will be pretty controlled, but another option is to look at the LUIS language understanding services from Microsoft, which are built exactly for understanding different parts of a text message, especially in a bot context. Here's a link to getting started with this, for C# (on the menu just below in this link, is a Node example if that's what you need).
There's also a tag here on Stack Overflow focused just on LUIS, if you run into trouble or need any more help.
Hope that helps
[Update] I re-read your question and I see now it's about BotComposer, not a custom developed bot. As a result, the sample I linked to is not valid, but LUIS certainly is. I haven't used Bot Composer myself, but LUIS is integrated as part of it - see here.

Ruby equivalent of ReadString?

I'm working on a project with a "customer made" database. He developed a C++/CLI application that stores and retrieves his data from a binary file using the BinaryWriter.Write(String) and BinaryReader.ReadString() methods.
I'm no C++/CLI expert but from what I understand these methods use a 7-bits encoding of the first bytes to determine the String length.
I need to access his data from a rail application, anyone's got an idea of how to do the same think in ruby?
If you're dealing with raw binary data, you'll probably need to spend some time familiarizing yourself with the pack and unpack methods and their various options. Maybe what you're describing is a "Pascal string" where the length is encoded up front, or a variation on that.
For example:
length = data.unpack("C")[0]
string = data.unpack("Ca#{length}")[0]
The double-unpack is required because you don't know the length of the string to unpack until you do the first step. You could probably do this using a substring as well, like data[1,length] if you're reasonably certain you're not dealing with UTF-8 data.

Where to keep long string to bind into textblock?

This is so stupid that I cannot find it anywhere!
Until now I used texblock with few words of text, so I just declared it as a property in text="my_short_text". Now I have several lines of text that I find really weird to put in the xaml.. I've tried to create a new text.txt resource file and tried to bind to the texblock with Path or Source but it didn't work! Where I have to keep my resourcese?
I know this is a noob question but I'm pretty new with WP7 and C#!
The use of an application resource file is where you'd want to store strings, ints, etc...
For WP7, there is an article on MSDN: How to: Build a Localized Application for Windows Phone. Scroll down to the section titled Replacing hard-coded strings with strings in a resource file.
There are examples of using resources all through the MSDN article; even though it's for localization, you can use the same concepts.

How to detect the Language set in the Windows phone

I need to detect the language of the phone so that I can display the message accordingly. If it is english , then display english. Say, I target a few countries such as China,japan, Korea. How do I do it? here my incomplete code to show what I mean:
tring StrLanSetOnClient;
string strLanEng= "english Msg";
string strLanChn=" Msg in chinese character";
string strLanJpn= "Msg in Japanese character";
string strLanKor= "Msg in Korean character" ;
strLanSetOnClient = CultureInfo..........
If( strLanSetOnClient == "English")
{
txtBlkLan.Text = strLanEng;
}
elseif ( strLanSetOnClient == "Chinese")
{
txtBlkLan.Text = strLanChn
}
....
Thanks
--- Updated Questions:
1) Where should I detect the language? In App.xaml?
2) How all pages can refer to this global variable name?
3) Which is the best practise to detect ? use CultureInfo or thread.currentThread
Thanks
&#lt;?xml version="1.0" encoding="utf-8"?&#gt;
&#lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&#gt;
&#lt;ProjectExtensions&#gt;
&#lt;VisualStudio &#gt;
&#lt;FlavorProperties GUID="{C089C8C0-30E0-4E22-80C0-CE093F11xxxx}"&#gt;
&#lt;SilverlightMobileCSProjectFlavor&#gt;
&#lt;FullDeploy &#gt; True &#lt;/FullDeploy&#gt;
&#lt;/SilverlightMobileCSProjectFlavor&#gt;
&#lt;/FlavorProperties&#gt;
&#lt;/VisualStudio&#gt;
&#lt;/ProjectExtensions&#gt;
&#lt;/Project&#gt;
This is the vanila csproj file of my Wp7 App. There is no SupportCulture tags in it. So, I have to add this tag in it right when I open it with notepad? When I downloaded your sample app, I open the csproj file with notepad, i dont see this tag either? Thanks
The way you're trying to do localization is to get very complicated, have lots of duplication and be difficult to change in the future.
There is a built in way of supporting multiple languages/cultures/etc. See http://msdn.microsoft.com/en-us/library/ff637522(v=vs.92).aspx
I wrote a blog on this very subject just the other day. It describes how to localize from start to finish, and it is located at www.hopnet.mobi, click Blogs.
Once you get the hang of it, localization really isn't difficult at all. I've localized one app, and I'm waiting on a friend to validate my translations. While she's doing that, I'm localizing the other apps. More languages means wider distribution, which means more money. You're doing the right thing!
Use CurrentCulture which is in your System.Globalization namespace. It has properties like Name, EnglishName, DisplayName and NativeName so you pick which one suits you most.
EDIT: Detecting the language will depend on whether you want to allow users to change the language or not. If not then detect it in App.xaml.cs and store the information in an IsolatedStorage object so that you can share it among different pages. This way you can avoid detecting the language settings later and just rely on the saved settings. As for the best practice I stick to CultureInfo. I never tried going directly through Thread.CurrentThread.

manually finding the size of a block of text (ASCII format)

Is there an easy way to manually (ie. not through code) find the size (in bytes, KB, etc) of a block of selected text? Currently I am taking the text, cutting/pasting into a new text document, saving it, then clicking "properties" to get an estimate of the size.
I am developing mainly in visual studio 2008 but I need any sort of simple way to manually do this.
Note: I understand this is not specifically a programming question but it's related to programming. I need this to compare a few functions and see which one is returning the smallest amount of text. I only need to do it a few times so figured writing a method for it would be overkill.
This question isn't meaningful as asked. Text can be encoded in different formats; ASCII, UTF-8, UTF-16, etc. The memory consumed by a block of text depends on which encoding you decide to use for it.
EDIT: To answer the question you've stated now (how do I determine which function is returning a "smaller" block of text) -- given a single encoding, the shorter text will almost always be smaller as well. Why can't you just compare the lengths?
In your comment you mention it's ASCII. In that case, it'll be one byte per character.
I don't see the difference between using the code written by the app you're pasting into, and using some other code. Being a python person myself, whenever I want to check length of some text I just do it in the interactive interpreter. Surely some equivalent solution more suited to your tastes would be appropriate?
ended up just cutting/pasting the text into MS Word and using the char count feature in there

Resources