-
-
Notifications
You must be signed in to change notification settings - Fork 130
[Snippets] Added String Manipulation Snippets for java #236
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9eb5875
case conversion snippets
Mcbencrafter 93a89b7
ascii/unicode to/from string conversion snippets
Mcbencrafter d532525
tab/space conversion snippets
Mcbencrafter aa6683b
palindrome/anagram check snippets
Mcbencrafter 872faf2
counting snippets
Mcbencrafter 7d7d077
normalisation snippets
Mcbencrafter aa4cd5f
reverse snippets
Mcbencrafter 7832e60
hide/truncate snippets
Mcbencrafter f5b07b5
slugify snippet
Mcbencrafter dee9622
password generator snippet
Mcbencrafter 0e1bf3a
text between delimiters extraction snippet
Mcbencrafter ea96f63
finding snippets
Mcbencrafter 51a63b1
renamed snippet for clarity
Mcbencrafter f330c02
corrected spaces to tabs snippet
Mcbencrafter 648c6bf
added accidentally removed file
Mcbencrafter 41c0404
tried to fix accidentally removed pre-commit file
Mcbencrafter abd118f
tried to revert pre commit file
Mcbencrafter 31ec9f8
Tried to restore pre-commit file
Mcbencrafter b1d436c
Merge branch 'main' into main
Mcbencrafter e15fc2a
replaced count consonants/vowels with a more generic snippet
Mcbencrafter 12abe5f
Merge branch 'main' of https://github.com/Mcbencrafter/quicksnip
Mcbencrafter c7b4d83
fixed remove punctuation snippet
Mcbencrafter 9f019a9
reset pre-commit file to origin/main because i messed up
Mcbencrafter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
password generator snippet
- Loading branch information
commit dee9622a9f84893a84e77f44db0d3cffd91b099f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: Password Generator | ||
description: Generates a random string with specified length and character set, including options for letters, numbers, and special characters | ||
author: Mcbencrafter | ||
tags: string,password,generator,security,random,token | ||
--- | ||
|
||
```java | ||
public static String randomString(int length, boolean useLetters, boolean useNumbers, boolean useSpecialCharacters) { | ||
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
String numbers = "0123456789"; | ||
String specialCharacters = "!@#$%^&*()_+-=[]{}|;:,.<>?"; | ||
|
||
String allowedCharacters = ""; | ||
|
||
if (useLetters) | ||
allowedCharacters += characters; | ||
|
||
if (useNumbers) | ||
allowedCharacters += numbers; | ||
|
||
if (useSpecialCharacters) | ||
allowedCharacters += specialCharacters; | ||
|
||
SecureRandom random = new SecureRandom(); | ||
StringBuilder result = new StringBuilder(length); | ||
|
||
for (int i = 0; i < length; i++) { | ||
int index = random.nextInt(allowedCharacters.length()); | ||
result.append(allowedCharacters.charAt(index)); | ||
} | ||
|
||
return result.toString(); | ||
} | ||
|
||
// Usage: | ||
System.out.println(randomString(10, true, true, false)); // Random string containing letters, numbers but no special characters with 10 characters | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.