Formatting Text in c# code

Riffy 276 Reputation points
2022-04-12T17:41:12.13+00:00

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,279 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vitoria Isabela de Oliveira 1 Reputation point
    2022-04-13T03:20:27.547+00:00

    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. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,451 Reputation points Microsoft Vendor
    2022-04-19T08:23:49.117+00:00

    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://learn.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://learn.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://learn.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.

    0 comments No comments