Hi, I am trying to find a neat way of getting a character at a specific index of a string.
I know to use .charAt(index), but I need it to be a string, not a char, and converting it to a string every time is a messy process.
gets quite messy when you need to do this for every comparison.
What I want is to use a loop to find a certain letter in a string, then check if both charAt(index - 1) AND charAt(index + 1) matches a specific character.
Note: I do NOT want to create an array of characters because the length of the string can vary greatly to the point where the array would be irrationally large, possibly lagging the program
newVar = String.valueOf(stringname.charAt(index));
//check if calculation contains any letters //regex: [a-zA-Z] means 'from "a" to "z" or from "A" to "Z" ' if (finalCalculation.matches("[a-zA-Z]")){ String character; for (int i = 0; i < finalCalculation.length(); i++){ //get character at index i and convert to string character = String.valueOf(finalCalculation.charAt(i)); //check if character is letter using regex (explained above) if (character.matches("[a-zA-Z]")){ if //unfinished; meant to be 'if character at index -1 and index +1 is "*" ' } } }