-
Notifications
You must be signed in to change notification settings - Fork 168
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
Proposal: procedure to count number of words in a string #852
Comments
Doesn't the split routine in fpm fulfill this purpose?
https://fortran-lang.github.io/fpm/proc/split.html
Regards,
Arjen
Op wo 31 jul 2024 om 08:59 schreef Ned Taylor ***@***.***>:
… Motivation
I regularly need to count the number of delimiter-separated fields in a
string.
When files have an arbitrary number of fields in a line, and you need to
read them in to an allocatable array. Reading the line to a buffer and
counting the number of fields in a line so that the array can first be
allocated is very handy.
This is also particularly useful in the following situation:
line = "Hello there how are you?
where the delimiter is repeated, and you want to just count the number of
delimiter-separated fields.
Prior Art
- wordcount (wc) in bash
Additional Information
*No response*
—
Reply to this email directly, view it on GitHub
<#852>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR73FY66RJB2JWQBR4DZPCDMRAVCNFSM6AAAAABLX2FSQSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZTSMRYG4ZTEOA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
@arjenmarkus. Quite possibly, depends on how you want to use it. I imagine that one would then use:
However, split works by storing in character arrays (from what I can see), so it uses up unnecessary memory if wanting to read integers or reals, or just get the number of fields on a line. I think there's still a use for it, but you may be completely right and I'm just overthinking this. |
This is a good idea, you could slightly modify the procedure to be a function returning by default the number of elements found in the line. Also, the output array can be an optional argument to avoid the allocation if not needed, for instance: https://godbolt.org/z/bz461x9G6 |
I support this idea. Note that |
Motivation
I regularly need to count the number of delimiter-separated fields in a string.
When files have an arbitrary number of fields in a line, and you need to read them in to an allocatable array. Reading the line to a buffer and counting the number of fields in a line so that the array can first be allocated is very handy.
This is also particularly useful in the following situation:
line = "Hello there how are you?
where the delimiter is repeated, and you want to just count the number of delimiter-separated fields.
Prior Art
Additional Information
No response
The text was updated successfully, but these errors were encountered: