question

Riffy-4263 avatar image
0 Votes"
Riffy-4263 asked vitoriaisabeladeoliveira-368 commented

Formatting Text in c# code

Hi

Is it possible to format text in actual c# code using control characters?

Example of c# code:

![192461-image.png


I am using Visual Studio 2022 code editor

I know you can specify \n for new line.

I don't want to create multiple XAML Label Text as there are several texts and their formats can vary.

Thanks


dotnet-csharpdotnet-xamarin
image.png (5.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

vitoriaisabeladeoliveira-368 avatar image
0 Votes"
vitoriaisabeladeoliveira-368 answered vitoriaisabeladeoliveira-368 commented

heey, riffy
How are you doing?
To manipulate and display strings, enums, dates, times, time intervals, numbers and quantities through C# code you can use the NuGet Humanizer package: with it everything becomes simpler, more accessible, more useful, more fluent, more flexible. For that, just create a console app now and install the Humanizer package and explore it!!!

Take a look at this NuGet link.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Vitoria

Sorry for delay in responding. My alerts were off, so didn't get responses.

So NuGet Humanizer will allow text formatting in actual C# code, as per my example above, before I explorer it further.

Thanks

0 Votes 0 ·

If the comment helped you, please interact by leaving your vote ;)

0 Votes 0 ·
WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered

Hello,

You may mean something like Markdown or HTML format, ** is for bold style, \n is for new line. I have to say, we can't format text directly by some control characters.
But you can display HTML text, refer to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/label#display-html
Labels expose a FormattedText property that allows the presentation of text with multiple fonts and colors in the same view. You could try to set attributes of the label, refer to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/label#formatted-text
And specific label by setting the Style properties, there are samples included in the document, you can check it: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/explicit

Best Regards,
Wenyan Zhang


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.