-
Notifications
You must be signed in to change notification settings - Fork 189
strings: join
, to_c_char
#936
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 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ab744c0
document `join`, `to_c_string`
perazz 5ee6bbb
add `join`, `to_c_string`
perazz 311d918
add `type(string_type)` version
perazz f958b74
add example
perazz f16afd2
test: to_c_string
perazz 0d27f92
test `join`
perazz e902e5c
`join`: add example
perazz 72e1c23
Update doc/specs/stdlib_strings.md
perazz 23e535b
`to_c_string` -> `to_c_char`: rename
perazz 6335dc0
Merge branch 'string_utilities' of https://github.com/perazz/stdlib i…
perazz 0f2165c
Update doc/specs/stdlib_strings.md
perazz 89df63a
Update example_to_c_char.f90
perazz 1b81e7e
Merge branch 'string_utilities' of https://github.com/perazz/stdlib i…
perazz f269996
Update example/strings/example_join.f90
perazz 1351a61
change result name to `joined`
perazz 1f24d54
Update stdlib_strings.md
perazz 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
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
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
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,21 @@ | ||
program example_join | ||
use stdlib_strings, only: join | ||
implicit none | ||
|
||
character(len=:), allocatable :: line | ||
character(*), parameter :: words(3) = [character(7) :: "Hello", "World", "Fortran"] | ||
|
||
! Default separator (space) | ||
line = join(words) | ||
print *, "'" // line // "'" !! 'Hello World Fortran' | ||
|
||
! Custom separator | ||
line = join(words, "_") | ||
print *, "'" // line // "'" !! 'Hello_World_Fortran' | ||
|
||
! Custom 2-character separator | ||
line = join(words, ", ") | ||
print *, "'" // line // "'" !! 'Hello, World, Fortran' | ||
|
||
stop 0 | ||
perazz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end program example_join |
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,22 @@ | ||
program example_to_c_string | ||
use stdlib_strings, only: to_c_string | ||
use stdlib_string_type, only: string_type | ||
use stdlib_kinds, only: c_char | ||
implicit none | ||
|
||
character(kind=c_char), allocatable :: cstr(:),cstr2(:) | ||
character(*), parameter :: hello = "Hello, World!" | ||
|
||
! Convert character array | ||
cstr = to_c_string(hello) | ||
|
||
! Convert string type | ||
cstr2 = to_c_string(string_type(hello)) | ||
|
||
if (size(cstr)==size(cstr2) .and. all(cstr==cstr2)) then | ||
stop 0 | ||
perazz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
error stop 'String conversion error' | ||
end if | ||
|
||
end program example_to_c_string |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.