Closed Hibees closed 9 years ago
If you're using C#, there are a few different ways to do this. If your text string is called 'str', you can use
str = str.First().ToString().ToUpper() + str.Substring(1);
Provided you check, first, that the string is not null or zero length.
Win2D is a tool more so for graphics than for text string manipulation. But there are different ways of doing this depending on the programming language you are using.
Does this help?
Closing this, but feel free to re-activate as needed.
I think I didn't explain my self, this is kind of related to my other issue " Wrap all text, CanvasTextLayout #86 " Imagine the text: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt I need this text to be wrapped by word on the canvasTextLayout so the canvasTextlayout make something like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
What I want is to have every first word on each line ToUpper Lorem ipsum dolor sit amet, Consectetur adipiscing elit, Sed do eiusmod tempor Incididunt
As I only set the text of the canvastextlayout, I can't find a way to know if the letter is the first one on each line visually. This is for a Karaoke type application where for Aesthetics-sake(don't know if correct use of the word) need to do this. Can this be done? Can I reactivate this?
Thanks for providing this context! I understand better now what this app is trying to do.
There isn't a feature built-in to Win2D to accomplish exactly this. With a little bit of code it should still be doable.
The app will have to "do the word-wrapping itself". Fortunately, CanvasTextLayout has GetCharacterRegions(). This returns a structure with a LayoutBounds, which returns the dimensions (width, height) of the text range you specify. From here, it should be possible to make a pretty simple word-wrapping routine, which divides your text string into an array of text strings. Then your app will manually capitalize the first letter of each text string in the array, using something like the code above.
Does this help? I agree this could be made easier.
This did the work, Thanks
GetCharacterRegions(1,text.length) This returns 1 CanvasTextLayoutRegion per line.
private String FirstLineCharactersToUpper(CanvasTextLayoutRegion[] textregions, String text)
{
char[] Textarray = text.ToCharArray();
foreach (CanvasTextLayoutRegion reg in textregions)
{
int index = reg.CharacterIndex;
char currentChar = text[index];
while (!char.IsLetter(currentChar))
index++;
Textarray[index] = char.ToUpper(Textarray[index]);
}
return new string(Textarray);
}
I need to capitalize the first letter of the first word on a line. I am not very fluid on C++, And don't know where to start to implement this feature.
Can this be added to the Backlog? Or how to perform this on C#?
Thanks for the help