Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 481 characters in body
Source Link

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

Edit:

I ended up placing a ~ after each special character in my array, and parsed it like this. Are there any issues in doing this?

/** Creating the names of the buttons. */ String [] buttonNames = { "Lsh", "Rsh", "Or", "Xor", "Not","And", "\uE752~", "Mod", "CE", "C", "\uF149~", "\uE94A~", "A", "B", "\uF14D~", "\uF14E~", "\uE94F~", "\uE947~", "C", "D", "\uF14A~", "\uF14B~", "\uF14C~", "\uE949~", "E", "F", "\uF14A~", "\uF14B~", "\uF14C~", "\uE948~", "(", ")", "\uE94D~", "0", ".", "\uE94E~" }; /** more code here */ if (buttons[i].getText().contains("~")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); buttons[i].setText(buttons[i].getText().substring(0, buttons[i].getText().lastIndexOf('~'))); } 

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

Edit:

I ended up placing a ~ after each special character in my array, and parsed it like this. Are there any issues in doing this?

if (buttons[i].getText().contains("~")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); buttons[i].setText(buttons[i].getText().substring(0, buttons[i].getText().lastIndexOf('~'))); } 

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

Edit:

I ended up placing a ~ after each special character in my array, and parsed it like this. Are there any issues in doing this?

/** Creating the names of the buttons. */ String [] buttonNames = { "Lsh", "Rsh", "Or", "Xor", "Not","And", "\uE752~", "Mod", "CE", "C", "\uF149~", "\uE94A~", "A", "B", "\uF14D~", "\uF14E~", "\uE94F~", "\uE947~", "C", "D", "\uF14A~", "\uF14B~", "\uF14C~", "\uE949~", "E", "F", "\uF14A~", "\uF14B~", "\uF14C~", "\uE948~", "(", ")", "\uE94D~", "0", ".", "\uE94E~" }; /** more code here */ if (buttons[i].getText().contains("~")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); buttons[i].setText(buttons[i].getText().substring(0, buttons[i].getText().lastIndexOf('~'))); } 
possible solution
Source Link

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

Edit:

I ended up placing a ~ after each special character in my array, and parsed it like this. Are there any issues in doing this?

if (buttons[i].getText().contains("~")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); buttons[i].setText(buttons[i].getText().substring(0, buttons[i].getText().lastIndexOf('~'))); } 

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

I'm trying to check to see if a string contains a specific unicode point from the Segoe MDL2 Assets font.

An example of a unicode value that I want to check for is

\uF14B 

Here's where I'm grabbing my values from

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font

How exactly can I check a string to see if it contains one of these values?

I have tried

 if (buttons[i].getText().contains("\uF14B")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); } 

While this does work, I think that it's pretty ineffecient to have to copy and paste each and every value that I plan to use into a if statement.

Is there an easier way to do this?

Edit:

I ended up placing a ~ after each special character in my array, and parsed it like this. Are there any issues in doing this?

if (buttons[i].getText().contains("~")) { buttons[i].setFont(new Font("Segoe MDL2 Assets", Font.PLAIN, 15 )); buttons[i].setText(buttons[i].getText().substring(0, buttons[i].getText().lastIndexOf('~'))); } 
edited title
Link

Check if java string contains unicode characters from specific font.character

Source Link
Loading