Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字符串的大小写取反 #50

Open
Sunny-117 opened this issue Nov 3, 2022 · 2 comments
Open

字符串的大小写取反 #50

Sunny-117 opened this issue Nov 3, 2022 · 2 comments

Comments

@Sunny-117
Copy link
Owner

let str = "QIANDUANGOngchengshi猕猴桃Jquery很帅!哈哈 haha";
str = str.replace(/[a-zA-Z]/g, (content) => {
  return content.toUpperCase() === content
    ? content.toLowerCase()
    : content.toUpperCase();
});
console.log(str);
@kangkang123269
Copy link

let str = "QIANDUANGOngchengshi猕猴桃Jquery很帅!哈哈 haha";

let result = "";

for (let i = 0; i < str.length; i++) {
  let char = str.charAt(i);
  if (char === char.toUpperCase()) {
    result += char.toLowerCase();
  } else {
    result += char.toUpperCase();
  }
}

console.log(result); // "qianduangONGCHENGSHI猕猴桃jQUERY很帅!哈哈 HAHA"

@veneno-o
Copy link
Contributor

let str = "React components wrap existing native code and interact with native APIs via React’s declarative UI paradigm and JavaScript. This enables native app development for whole new teams of developers, and can let existing native teams work much faster."
str = String(str).replace(/([a-zA-z])/g, function(text){
    return text.toLowerCase() === text ? text.toUpperCase() : text.toLowerCase()
})
console.log(str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants